From 0f53fc83289911a512799e013473f9fddc8f2217 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 6 May 2015 07:33:32 +1000 Subject: [PATCH] correct emergency regeneration in the controller --- app/controllers/stylesheets_controller.rb | 3 ++- app/models/stylesheet_cache.rb | 4 +++- spec/models/stylesheet_cache_spec.rb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/stylesheets_controller.rb b/app/controllers/stylesheets_controller.rb index af6e34048..688b05ad1 100644 --- a/app/controllers/stylesheets_controller.rb +++ b/app/controllers/stylesheets_controller.rb @@ -5,6 +5,7 @@ class StylesheetsController < ApplicationController target,digest = params[:name].split("_") + digest_orig = digest digest = "_" + digest if digest # Security note, safe due to route constraint @@ -13,7 +14,7 @@ class StylesheetsController < ApplicationController unless File.exist?(location) query = StylesheetCache.where(target: target) if digest - query = query.where(digest: digest) + query = query.where(digest: digest_orig) else query = query.order('id desc') end diff --git a/app/models/stylesheet_cache.rb b/app/models/stylesheet_cache.rb index 152db2484..331fb1365 100644 --- a/app/models/stylesheet_cache.rb +++ b/app/models/stylesheet_cache.rb @@ -12,7 +12,9 @@ class StylesheetCache < ActiveRecord::Base count = StylesheetCache.count if count > MAX_TO_KEEP - remove_lower = StylesheetCache.limit(MAX_TO_KEEP) + remove_lower = StylesheetCache + .where(target: target) + .limit(MAX_TO_KEEP) .order('id desc') .pluck(:id) .last diff --git a/spec/models/stylesheet_cache_spec.rb b/spec/models/stylesheet_cache_spec.rb index 8438aba7b..ef26433bb 100644 --- a/spec/models/stylesheet_cache_spec.rb +++ b/spec/models/stylesheet_cache_spec.rb @@ -5,7 +5,7 @@ describe StylesheetCache do describe "add" do it "correctly cycles once MAX_TO_KEEP is hit" do (StylesheetCache::MAX_TO_KEEP + 1).times do |i| - StylesheetCache.add(i.to_s, "d" + i.to_s, "c" + i.to_s) + StylesheetCache.add("a", "d" + i.to_s, "c" + i.to_s) end expect(StylesheetCache.count).to eq StylesheetCache::MAX_TO_KEEP