diff options
-rw-r--r-- | app/controllers/application_controller.rb | 37 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 6 | ||||
-rw-r--r-- | app/views/request/_after_actions.rhtml | 2 | ||||
-rw-r--r-- | app/views/request/_correspondence.rhtml | 2 |
4 files changed, 29 insertions, 18 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3b60d69c1..9ee1c250b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -91,6 +91,27 @@ class ApplicationController < ActionController::Base controller_example_group.get params[:action], params end + # Used to work out where to cache fragments. We add an extra path to the + # URL using the first three digits of the info request id, because we can't + # have more than 32,000 entries in one directory on an ext3 filesystem. + def foi_fragment_cache_part_path(param) + path = url_for(param) + id = param['id'] || param[:id] + first_three_digits = id.to_s()[0..2] + path = path.sub("/request/", "/request/" + first_three_digits + "/") + return path + end + def foi_fragment_cache_path(param) + path = foi_fragment_cache_part_path(param) + 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] + path = "views/request/#{first_three_digits}/#{info_request.id}" + return File.join(self.cache_store.cache_path, path) + end + private # Check the user is logged in @@ -253,22 +274,6 @@ class ApplicationController < ActionController::Base expires_in max_age.minutes, :private => false end - # Used to work out where to cache fragments. We add an extra path to the - # URL using the first three digits of the info request id, because we can't - # have more than 32,000 entries in one directory on an ext3 filesystem. - def foi_fragment_cache_path(param) - path = url_for(param) - first_three_digits = param['id'].to_s()[0..2] - path = path.sub("/request/", "/request/" + first_three_digits + "/") - 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] - 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), # views (for links) and mailers (for use in emails), so include them into # all of all. diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7cc0b0e5d..08908abee 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -59,5 +59,11 @@ module ApplicationHelper t = highlight_words(t, words, html) return t end + + # Use our own algorithm for finding path of cache + def foi_cache(name = {}, options = nil, &block) + name = @controller.foi_fragment_cache_part_path(name) + @controller.fragment_for(output_buffer, name, options, &block) + end end diff --git a/app/views/request/_after_actions.rhtml b/app/views/request/_after_actions.rhtml index d51c6bfb3..9bef04ce4 100644 --- a/app/views/request/_after_actions.rhtml +++ b/app/views/request/_after_actions.rhtml @@ -24,7 +24,7 @@ <% if @last_response.nil? %> <%= link_to "Send follow up to " + OutgoingMailer.name_for_followup(@info_request, @last_response), show_response_no_followup_url(:id => @info_request.id, :incoming_message_id => nil) + "#followup" %> <% else %> - <% cache(:controller => "request", :action => "show_response", :id => @info_request.id, :incoming_message_id => @last_response.id, :only_path => true, :template => "_after_actions", :section => "reply_to_link") do %> + <% foi_cache(:controller => "request", :action => "show_response", :id => @info_request.id, :incoming_message_id => @last_response.id, :only_path => true, :template => "_after_actions", :section => "reply_to_link") do %> <%= link_to "Reply to " + OutgoingMailer.name_for_followup(@info_request, @last_response), show_response_url(:id => @info_request.id, :incoming_message_id => @last_response.id) + "#followup" %> <% end %> <% end %> diff --git a/app/views/request/_correspondence.rhtml b/app/views/request/_correspondence.rhtml index 90beb4050..0756b0797 100644 --- a/app/views/request/_correspondence.rhtml +++ b/app/views/request/_correspondence.rhtml @@ -6,7 +6,7 @@ end if not incoming_message.nil? %> <div class="correspondence" id="incoming-<%=incoming_message.id.to_s%>"> - <% cache(:controller => "request", :action => "show_response", :id => @info_request.id, :incoming_message_id => incoming_message.id, :only_path => true, :template => "_correspondence", :section => "incoming_message_bubble", :collapse => @collapse_quotes ? nil : 'no' ) do %> + <% foi_cache(:controller => "request", :action => "show_response", :id => @info_request.id, :incoming_message_id => incoming_message.id, :only_path => true, :template => "_correspondence", :section => "incoming_message_bubble", :collapse => @collapse_quotes ? nil : 'no' ) do %> <h2> <% if !incoming_message.safe_mail_from.nil? && incoming_message.safe_mail_from.strip != @info_request.public_body.name.strip %> <%=h incoming_message.safe_mail_from %><br> |