]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5048 Fix regression when ES search returns no result
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 21 Feb 2014 10:21:20 +0000 (11:21 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 21 Feb 2014 10:31:13 +0000 (11:31 +0100)
sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb

index 97d5122ab3cf163533c742005f0b8a607476cac3..ee32d1e80f5180077a18e389dbdd85fecc54be61 100644 (file)
@@ -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