aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2009-09-15 20:46:35 +0000
committerfrancis <francis>2009-09-15 20:46:35 +0000
commit658903402044edbeaae45c4b573cb0d94db31623 (patch)
tree286ea9cdd22bffb5e933ea4e86d0e243f773dbaa
parent33fd5b4a0ce59dfee960d35910e8c4bdee14bb28 (diff)
Replace expires_fragment with actual fast alternative!
-rw-r--r--app/controllers/admin_controller.rb28
1 files changed, 15 insertions, 13 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 32681c18d..32882f8a4 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -4,8 +4,9 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: admin_controller.rb,v 1.27 2009-08-21 17:43:33 francis Exp $
+# $Id: admin_controller.rb,v 1.28 2009-09-15 20:46:35 francis Exp $
+require 'fileutils'
class AdminController < ApplicationController
layout "admin"
@@ -18,20 +19,21 @@ class AdminController < ApplicationController
# Expire cached attachment files for a request
def expire_for_request(info_request)
- # Clear out cached entries - use low level expire_fragment, even though
- # we are clearing results from caches_action, for several reasons:
- # * We can't use expire_action here, as doesn't seem to be
+ # Clear out cached entries - use low level disk removal, even though we
+ # are clearing results from caches_action, for several reasons:
+ # * We can't use expire_action here, as it doesn't seem to be
# compatible with the :only_path we used in the caches_action
# call.
- # * expire_fragment lets us use a regular expression which is
- # simpler than having to get all the parameters right for the
- # path, and calling for HTML version vs. raw attachment version.
- # * Regular expression means we cope properly with filenames
- # changed by censor rules, which change the URL.
- # * It's also possible to load a file with any name by changing
- # the URL, the regular expression makes sure the cache is
- # cleared even if someone did that.
- expire_fragment /views\/request\/#{info_request.id}.*/
+ # * Removing everything is simpler than having to get all the
+ # parameters right for the path, and calling for HTML version vs. raw
+ # attachment version.
+ # * We cope properly with filenames changed by censor rules, which
+ # change the URL.
+ # * We could use expire_fragment with a Regexp, but it walks the whole
+ # cache which is insanely slow
+ cache_subpath = File.join(self.cache_store.cache_path, "views/request/#{info_request.id}")
+ FileUtils.rm_rf(cache_subpath)
+
# also force a search reindexing (so changed text reflected in search)
info_request.reindex_request_events
end