From b9f5c32755f53ae67cc49976b336746ecd5af72a Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sat, 10 Jan 2009 22:33:30 -0600 Subject: [PATCH] Cache file_list Action Also, slightly smarter cache expiry, upon uploading/deleting a file. --- app/controllers/cache_sweeping_helper.rb | 6 +++++- app/controllers/web_sweeper.rb | 11 +++++++++-- app/controllers/wiki_controller.rb | 2 +- app/views/wiki/file_list.html.erb | 2 +- config/routes.rb | 1 + 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/controllers/cache_sweeping_helper.rb b/app/controllers/cache_sweeping_helper.rb index a960291c..249b2f77 100644 --- a/app/controllers/cache_sweeping_helper.rb +++ b/app/controllers/cache_sweeping_helper.rb @@ -16,9 +16,13 @@ module CacheSweepingHelper end end - %w(authors atom_with_content atom_with_headlines).each do |action| + %w(authors atom_with_content atom_with_headlines file_list).each do |action| expire_action :controller => 'wiki', :web => web.address, :action => action end + + %w(file_name created_at).each do |sort_order| + expire_action :controller => 'wiki', :web => web.address, :action => 'file_list', :sort_order => sort_order + end end end diff --git a/app/controllers/web_sweeper.rb b/app/controllers/web_sweeper.rb index 81ebf141..8ffb05fc 100644 --- a/app/controllers/web_sweeper.rb +++ b/app/controllers/web_sweeper.rb @@ -4,13 +4,18 @@ class WebSweeper < ActionController::Caching::Sweeper include CacheSweepingHelper - observe Web, Page + observe Web, Page, WikiFile def after_save(record) if record.is_a?(Web) web = record web.pages.each { |page| expire_cached_page(web, page.name) } expire_cached_summary_pages(web) + elsif record.is_a?(WikiFile) + record.web.pages_that_link_to(record.file_name).each do |page| + expire_cached_page(record.web, page) + end + expire_cached_summary_pages(record.web) end end @@ -25,9 +30,11 @@ class WebSweeper < ActionController::Caching::Sweeper def after_destroy(record) if record.is_a?(Web) expire_cached_summary_pages(record) - else + elsif record.is_a?(Page) expire_cached_page(record.web, record.name) expire_cached_summary_pages(record.web) + else + expire_cached_summary_pages(record.web) end end diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 535970b2..b068c401 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -8,7 +8,7 @@ class WikiController < ApplicationController before_filter :load_page before_filter :dnsbl_check, :only => [:edit, :new, :save, :export_html, :export_markup] - caches_action :show, :published, :authors, :tex, :s5, :print, :recently_revised, :list, + caches_action :show, :published, :authors, :tex, :s5, :print, :recently_revised, :list, :file_list, :atom_with_content, :atom_with_headlines, :if => Proc.new { |c| c.send(:do_caching?) } cache_sweeper :revision_sweeper diff --git a/app/views/wiki/file_list.html.erb b/app/views/wiki/file_list.html.erb index ffff9921..09db001d 100644 --- a/app/views/wiki/file_list.html.erb +++ b/app/views/wiki/file_list.html.erb @@ -20,7 +20,7 @@ <%= file.file_name%> (<%= file.created_at.asctime %>) <%= "Linked to by: " unless @web.pages_that_link_to(file.file_name).empty? -%> - <%= @web.pages_that_link_to(file.file_name).collect { |referring_page| link_to referring_page }.join(", ") %> + <%= @web.pages_that_link_to(file.file_name).collect { |referring_page| link_to_page(referring_page) }.join(", ") %> <%- end -%> diff --git a/config/routes.rb b/config/routes.rb index e9e08492..e361d89e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,7 @@ ActionController::Routing::Routes.draw do |map| connect_to_web map, ':web/remove_orphaned_pages_in_category', :controller => 'admin', :action => 'remove_orphaned_pages_in_category' connect_to_web map, ':web/file/delete/:id', :controller => 'file', :action => 'delete', :requirements => {:id => /[-._\w]+/}, :id => nil connect_to_web map, ':web/files/:id', :controller => 'file', :action => 'file', :requirements => {:id => /[-._\w]+/}, :id => nil + connect_to_web map, ':web/file_list/:sort_order', :controller => 'wiki', :action => 'file_list', :sort_order => nil connect_to_web map, ':web/import/:id', :controller => 'file', :action => 'import' connect_to_web map, ':web/login', :controller => 'wiki', :action => 'login' connect_to_web map, ':web/web_list', :controller => 'wiki', :action => 'web_list'