From: Julien Lancelot Date: Thu, 22 Nov 2012 10:40:37 +0000 (+0100) Subject: SONAR-3790 use distinct keywords in db query instead of a set to remove duplicate... X-Git-Tag: 3.4~304 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ce05979da59099aaa3441828398d1cd06a60e883;p=sonarqube.git SONAR-3790 use distinct keywords in db query instead of a set to remove duplicate results --- diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb index af39a4fbd7c..174701c15c4 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb @@ -45,7 +45,7 @@ class Api::ResourcesController < Api::ApiController condition_values< 'resource_id,root_project_id,qualifier', # optimization to not load unused columns like 'kee' + :select => 'distinct(resource_id),root_project_id,qualifier', # optimization to not load unused columns like 'kee' :conditions => [conditions.join(' and ')].concat(condition_values), :order => 'name_size') diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb index 1d8c239389c..cee1eda2f04 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb @@ -47,7 +47,7 @@ class BulkDeletionController < ApplicationController end resource_ids = ResourceIndex.find(:all, - :select => 'resource_id', + :select => 'distinct(resource_id)', :conditions => [conditions, values], :order => 'name_size').map {|rid| rid.resource_id}.uniq diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb index bbc80bb41f8..90277e674de 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb @@ -33,12 +33,11 @@ class SearchController < ApplicationController key = search.downcase results = ResourceIndex.find(:all, - :select => 'resource_id,root_project_id,qualifier', # optimization to not load unused columns like 'kee' + :select => 'distinct(resource_id),root_project_id,qualifier', # optimization to not load unused columns like 'kee' :conditions => ["kee like ?", key + '%'], :order => 'name_size') results = select_authorized(:user, results) - results = Set.new(results) # do not want the same resource_index to appear many times in the result @total = results.size resource_ids=[] diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/resource_index.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/resource_index.rb index 6a3b4770d88..7f8b1b3c057 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/resource_index.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/resource_index.rb @@ -30,12 +30,4 @@ class ResourceIndex < ActiveRecord::Base root_project_id end - def eql?(another_resource_index) - resource_id == another_resource_index.resource_id && root_project_id == another_resource_index.root_project_id - end - - def hash - [resource_id, root_project_id].hash - end - end \ No newline at end of file