From: Jean-Baptiste Lievremont Date: Fri, 21 Feb 2014 10:21:20 +0000 (+0100) Subject: SONAR-5048 Fix regression when ES search returns no result X-Git-Tag: 4.2~69 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=478d79afd5deae6eb0419f68e933079b32b2d08e;p=sonarqube.git SONAR-5048 Fix regression when ES search returns no result --- diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb index 97d5122ab3c..ee32d1e80f5 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb @@ -268,15 +268,19 @@ class Rule < ActiveRecord::Base params = java.util.HashMap.new(java_hash) # SONAR-5048 Group results by 1000 due to fix issue on Oracle db - ids_grouped = Array(Internal.rrules.findIds(params)).each_slice(1000).to_a - ids_condition = [] - ids_grouped.each do |group| - ids_condition << 'id in (' + group.join(',') + ')' - end + rules = [] + matching_rule_ids = Array(Internal.rrules.findIds(params)) + unless matching_rule_ids.empty? + ids_grouped = matching_rule_ids.each_slice(1000).to_a + ids_condition = [] + ids_grouped.each do |group| + ids_condition << 'id in (' + group.join(',') + ')' + end - includes=(options[:include_parameters_and_notes] ? [:rules_parameters] : nil) - rules = Rule.all(:include => includes, :conditions => [ids_condition.join(' or ')]) - rules = Rule.sort_by(rules, options[:sort_by]) + includes=(options[:include_parameters_and_notes] ? [:rules_parameters] : nil) + rules = Rule.all(:include => includes, :conditions => [ids_condition.join(' or ')]) + rules = Rule.sort_by(rules, options[:sort_by]) + end filter(rules, options) end