From c0ccd41eb7a3654fb6dca272b7bfbcfdcc5ac7ef Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 20 Feb 2013 10:21:57 +0100 Subject: [PATCH] SONAR-4140 fix performance of /api/batch_bootstrap/properties --- .../app/controllers/batch_bootstrap_controller.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/batch_bootstrap_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/batch_bootstrap_controller.rb index 9c2055bbffe..52d1c8c134b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/batch_bootstrap_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/batch_bootstrap_controller.rb @@ -36,8 +36,13 @@ class BatchBootstrapController < Api::ApiController root_project = load_project() if root_project - Project.find(:all, :select => 'id,kee', :conditions => ['enabled=? and (root_id=? or id=?)', true, root_project.id, root_project.id]).each do |project| - json_properties.concat(Property.find(:all, :conditions => ['user_id is null and resource_id=?', project.id]).map { |property| to_json_property(property, project.kee) }) + properties = Property.find(:all, :conditions => ["user_id is null and resource_id in (select id from projects where enabled=? and (root_id=? or id=?))", true, root_project.id, root_project.id]) + resource_ids = properties.map{|p| p.resource_id}.uniq.compact + unless resource_ids.empty? + resource_key_by_id = Project.find(:all, :select => 'id,kee', :conditions => {:id => resource_ids}).inject({}) {|hash, resource| hash[resource.id]=resource.key; hash} + properties.each do |property| + json_properties << to_json_property(property, resource_key_by_id[property.resource_id]) + end end end -- 2.39.5