From 67d69ce1f8f81f44c0099e631d0ba95fc02d9763 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Thu, 30 Apr 2015 17:30:15 +0100 Subject: Reduce N+1 queries getting new body requests Removes the following Bullet warnings: N+1 Query detected PublicBodyChangeRequest => [:public_body] Add to your finder: :includes => [:public_body] N+1 Query method call stack /home/vagrant/alaveteli/app/models/public_body_change_request.rb:65:in `get_public_body_name' /home/vagrant/alaveteli/app/views/admin_general/_change_request_summary.html .erb:8:in `_app_views_admin_general__change_request_summary_html_erb__490351475_701155 42681500' /home/vagrant/alaveteli/app/views/admin_general/index.html.erb:191:in `_app_views_admin_general_index_html_erb___48164640_70115537288900' /home/vagrant/alaveteli/app/views/admin_general/index.html.erb:190:in `_app_views_admin_general_index_html_erb___48164640_70115537288900' /home/vagrant/alaveteli/app/controllers/application_controller.rb:111:in `record_memory' /home/vagrant/alaveteli/lib/whatdotheyknow/strip_empty_sessions.rb:14:in `call' N+1 Query detected PublicBodyChangeRequest => [:user] Add to your finder: :includes => [:user] N+1 Query method call stack /home/vagrant/alaveteli/app/models/public_body_change_request.rb:57:in `get_user_name' /home/vagrant/alaveteli/app/views/admin_general/_change_request_summary.html .erb:46:in `_app_views_admin_general__change_request_summary_html_erb__490351475_701155 42681500' /home/vagrant/alaveteli/app/views/admin_general/index.html.erb:191:in `_app_views_admin_general_index_html_erb___48164640_70115537288900' /home/vagrant/alaveteli/app/views/admin_general/index.html.erb:190:in `_app_views_admin_general_index_html_erb___48164640_70115537288900' /home/vagrant/alaveteli/app/controllers/application_controller.rb:111:in `record_memory' /home/vagrant/alaveteli/lib/whatdotheyknow/strip_empty_sessions.rb:14:in `call' --- app/controllers/admin_general_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/controllers/admin_general_controller.rb') diff --git a/app/controllers/admin_general_controller.rb b/app/controllers/admin_general_controller.rb index 3eaabda81..35f872666 100644 --- a/app/controllers/admin_general_controller.rb +++ b/app/controllers/admin_general_controller.rb @@ -31,7 +31,10 @@ class AdminGeneralController < AdminController @old_unclassified = InfoRequest.find_old_unclassified(:limit => 20, :conditions => ["prominence = 'normal'"]) @holding_pen_messages = InfoRequest.holding_pen_request.incoming_messages - @new_body_requests = PublicBodyChangeRequest.new_body_requests.open + @new_body_requests = PublicBodyChangeRequest. + includes(:public_body, :user). + new_body_requests. + open @body_update_requests = PublicBodyChangeRequest.body_update_requests.open end -- cgit v1.2.3