diff options
Diffstat (limited to 'app/controllers/general_controller.rb')
-rw-r--r-- | app/controllers/general_controller.rb | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index bdbcfcdd4..21f3edbb1 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -20,19 +20,35 @@ class GeneralController < ApplicationController # New, improved front page! def frontpage - # This is too slow + + behavior_cache 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 = MySociety::Config.get('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] PublicBody.with_locale(@locale) do - @popular_bodies = PublicBody.find(:all, - :select => "public_bodies.*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c", - :order => "c desc", - :limit => 32, - :conditions => conditions, - :joins => :translations - ) - end + if body_short_names.empty? + # This is too slow + @popular_bodies = PublicBody.find(:all, + :select => "public_bodies.*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c", + :order => "c desc", + :limit => 32, + :conditions => conditions, + :joins => :translations + ) + else + @popular_bodies = PublicBody.find(:all, + :conditions => conditions + ["url_name in (" + body_short_names + ")"], + :joins => :translations) + end + end + @search_examples = MySociety::Config.get('FRONTPAGE_SEARCH_EXAMPLES', '').split(/\s*;\s*/) + if @search_examples.empty? + @search_examples = @popular_bodies.map { |body| body.name } + end # Get some successful requests # begin query = 'variety:response (status:successful OR status:partially_successful)' @@ -44,6 +60,7 @@ class GeneralController < ApplicationController rescue @successful_request_events = [] end + end end # Display WhatDoTheyKnow category from mySociety blog |