From 478d79afd5deae6eb0419f68e933079b32b2d08e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Fri, 21 Feb 2014 11:21:20 +0100 Subject: [PATCH] SONAR-5048 Fix regression when ES search returns no result --- .../main/webapp/WEB-INF/app/models/rule.rb | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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 -- 2.39.5