diff options
author | Matthew Landauer <matthew@openaustralia.org> | 2013-01-31 08:21:22 +1100 |
---|---|---|
committer | Matthew Landauer <matthew@openaustralia.org> | 2013-01-31 08:31:44 +1100 |
commit | 6df81c66932773b4a461816c9cd6b85cf7157776 (patch) | |
tree | 88c2ba867afab54251bc8a33136ec05a17c6b940 /app/controllers/general_controller.rb | |
parent | 26c9c6a3f0f5bb33fa52841d5854bf52b7cf2e20 (diff) | |
parent | afa9ef14323dfbfd412f0c8872e0b3736d60e7a3 (diff) |
Merge branch 'i18n_rails3_preparation' into rails-3-spike
Conflicts:
Gemfile.lock
app/controllers/general_controller.rb
app/controllers/public_body_controller.rb
spec/controllers/public_body_controller_spec.rb
Diffstat (limited to 'app/controllers/general_controller.rb')
-rw-r--r-- | app/controllers/general_controller.rb | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index faf34aa04..003b815d3 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -19,26 +19,28 @@ class GeneralController < ApplicationController # New, improved front page! def frontpage medium_cache - # get some example searches and public bodies to display - # either from config, or based on a (slow!) query if not set - body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") - @locale = self.locale_from_params() - locale_condition = 'public_body_translations.locale = ?' - conditions = [locale_condition, @locale] - I18n.with_locale(@locale) do - if body_short_names.empty? - # This is too slow - @popular_bodies = PublicBody.visible.find(:all, - :order => "info_requests_count desc", - :limit => 32, - :conditions => conditions, - :joins => :translations - ) - else - conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")" - @popular_bodies = PublicBody.find(:all, - :conditions => conditions, - :joins => :translations) + behavior_cache :tag => [session[:user_id], request.url] do + # get some example searches and public bodies to display + # either from config, or based on a (slow!) query if not set + body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") + @locale = self.locale_from_params() + locale_condition = 'public_body_translations.locale = ?' + conditions = [locale_condition, @locale] + I18n.with_locale(@locale) do + if body_short_names.empty? + # This is too slow + @popular_bodies = PublicBody.visible.find(:all, + :order => "info_requests_count desc", + :limit => 32, + :conditions => conditions, + :joins => :translations + ) + else + conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")" + @popular_bodies = PublicBody.find(:all, + :conditions => conditions, + :joins => :translations) + end end end # Get some successful requests |