diff options
author | Gareth Rees <gareth@mysociety.org> | 2015-04-21 12:49:59 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2015-04-27 16:17:11 +0100 |
commit | 5cbf0836c049d5b9039fefb64a39e81aa8eb6b5e (patch) | |
tree | 4aa330a71074ec705ff3c1db05e85e1990ca930e | |
parent | a960380f1a6aa2b2aacfa726adc41a09ea89f1d0 (diff) |
Reduce N+1 queries in RequestGameController#play
Eliminates the following Bullet warnings:
2015-04-21 11:42:26[WARN] /categorise/play
N+1 Query detected
user: vagrant
InfoRequest => [:public_body]
Add to your finder: :includes => [:public_body]
N+1 Query method call stack
/home/vagrant/alaveteli/app/views/request/_request_listing_single.html.erb:16:in `_app_views_request__request_listing_single_html_erb__949797960_70091194573720'
/home/vagrant/alaveteli/app/views/request_game/play.html.erb:46:in `_app_views_request_game_play_html_erb___279307748_70091194720080'
/home/vagrant/alaveteli/app/views/request_game/play.html.erb:45:in `each'
/home/vagrant/alaveteli/app/views/request_game/play.html.erb:45:in `_app_views_request_game_play_html_erb___279307748_70091194720080'
/home/vagrant/alaveteli/app/controllers/application_controller.rb:111:in `record_memory'
/home/vagrant/alaveteli/lib/whatdotheyknow/strip_empty_sessions.rb:14:in `call'
2015-04-21 11:42:26[WARN] /categorise/play
N+1 Query detected
user: vagrant
InfoRequest => [:user]
Add to your finder: :includes => [:user]
N+1 Query method call stack
/home/vagrant/alaveteli/app/views/request/_request_listing_single.html.erb:17:in `_app_views_request__request_listing_single_html_erb__949797960_70091194573720'
/home/vagrant/alaveteli/app/views/request_game/play.html.erb:46:in `_app_views_request_game_play_html_erb___279307748_70091194720080'
/home/vagrant/alaveteli/app/views/request_game/play.html.erb:45:in `each'
/home/vagrant/alaveteli/app/views/request_game/play.html.erb:45:in `_app_views_request_game_play_html_erb___279307748_70091194720080'
/home/vagrant/alaveteli/app/controllers/application_controller.rb:111:in `record_memory'
/home/vagrant/alaveteli/lib/whatdotheyknow/strip_empty_sessions.rb:14:in `call'
-rw-r--r-- | app/controllers/request_game_controller.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/app/controllers/request_game_controller.rb b/app/controllers/request_game_controller.rb index 298818bc7..7eadc1204 100644 --- a/app/controllers/request_game_controller.rb +++ b/app/controllers/request_game_controller.rb @@ -13,7 +13,8 @@ class RequestGameController < ApplicationController @total = InfoRequest.count @done = @total - @missing @percentage = (@done.to_f / @total.to_f * 10000).round / 100.0 - @requests = InfoRequest.get_random_old_unclassified(3, :conditions => ["prominence = 'normal'"]) + @requests = InfoRequest.includes(:public_body, :user).get_random_old_unclassified(3, :conditions => ["prominence = 'normal'"]) + if @missing == 0 flash[:notice] = _('<p>All done! Thank you very much for your help.</p><p>There are <a href="{{helpus_url}}">more things you can do</a> to help {{site_name}}.</p>', |