diff options
-rw-r--r-- | app/controllers/admin_controller.rb | 16 | ||||
-rw-r--r-- | app/controllers/application_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 11 | ||||
-rw-r--r-- | todo.txt | 4 |
4 files changed, 19 insertions, 18 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 48e223cea..ca5538e03 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -19,19 +19,9 @@ class AdminController < ApplicationController # Expire cached attachment files for a request def expire_for_request(info_request) - # 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. - # * 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, foi_fragment_cache_all_for_request(info_request)) + # Clear out cached entries, by removing files from disk (the built in + # Rails fragment cache made doing this and other things too hard) + cache_subpath = foi_fragment_cache_all_for_request(info_request) FileUtils.rm_rf(cache_subpath) # Remove the database caches of body / attachment text (the attachment text diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index be555b291..3b60d69c1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -260,11 +260,13 @@ class ApplicationController < ActionController::Base path = url_for(param) first_three_digits = param['id'].to_s()[0..2] path = path.sub("/request/", "/request/" + first_three_digits + "/") - path = path.sub(/^\//, "") # remove initial slash + path = "/views" + path + return File.join(self.cache_store.cache_path, path) end def foi_fragment_cache_all_for_request(info_request) first_three_digits = info_request.id.to_s()[0..2] - return "views/request/#{first_three_digits}/#{info_request.id}" + path = "views/request/#{first_three_digits}/#{info_request.id}" + return File.join(self.cache_store.cache_path, path) end # URL generating functions are needed by all controllers (for redirects), diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 120bb38ce..1357f993b 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -548,7 +548,8 @@ class RequestController < ApplicationController key = params.merge(:only_path => true) key_path = foi_fragment_cache_path(key) - if cached = read_fragment(key_path) + if File.exists?(key_path) + cached = File.read(key_path) IncomingMessage # load global filename_to_mimetype XXX should move filename_to_mimetype to proper namespace response.content_type = filename_to_mimetype(params[:file_name].join("/")) or 'application/octet-stream' render_for_text(cached) @@ -557,7 +558,11 @@ class RequestController < ApplicationController yield - write_fragment(key_path, response.body) + # write it to the fileystem ourselves, so is just a plain file. (The + # various fragment cache functions using Ruby Marshall to write the file + # which adds a header, so isnt compatible with images that have been + # extracted elsewhere from PDFs) + File.open(key_path, 'wb') {|f| f.write(response.body) } end def get_attachment @@ -580,7 +585,7 @@ class RequestController < ApplicationController # the same cache code in cache_attachments above will display them. key = params.merge(:only_path => true) key_path = foi_fragment_cache_path(key) - image_dir = File.dirname(ActionController::Base.cache_store.cache_path + "/views" + key_path) + image_dir = File.dirname(key_path) FileUtils.mkdir_p(image_dir) html, wrapper_id = @attachment.body_as_html(image_dir) @@ -68,6 +68,10 @@ http://www.activemerchant.org/ Performance =========== +Enable Directory Indexing, and disable atime (@glynwintle suggests) +http://www.softpanorama.org/Internals/Filesystems/linux_ext2_ext3.shtml +(as/if we have caches with lots of files in a direcory) + test if get_attachments_for_display called multiple times in one request? Some requests to lower memory use of still: |