]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2535 The resource viewer displays an error message when there are more than...
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 20 Jun 2011 10:04:08 +0000 (12:04 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 20 Jun 2011 10:08:47 +0000 (12:08 +0200)
sonar-server/src/main/webapp/WEB-INF/config/environment.rb
sonar-server/src/main/webapp/WEB-INF/vendor/rails/activerecord/lib/active_record/association_preload.rb

index cf15d6a5a3134ac5f37104e10ba4b3be98512a08..2aaca86abb76dfb4021e0100d1947e6949331202 100644 (file)
@@ -237,7 +237,7 @@ end
 #
 # other patches :
 # - activerecord : fix Oracle bug when more than 1000 elements in IN clause. See lib/active_record/association_preload.rb
-#   See https://rails.lighthouseapp.com/projects/8994/tickets/1533-preloading-more-than-1000-associated-records-causes-activerecordstatementinvalid-when-using-oracle
+#   See https://github.com/rails/rails/issues/585
 # - actionview NumberHelper, patch for number_with_precision()
 
 require File.dirname(__FILE__) + '/../lib/sonar_webservice_plugins.rb'
index d95e41c0f1415145d1148776d22d78d14c9c7210..e3802d92568df3f2ec8f07b676577f0200834e4b 100755 (executable)
@@ -355,13 +355,13 @@ module ActiveRecord
           end
           conditions = "#{table_name}.#{connection.quote_column_name(primary_key)} #{in_or_equals_for_ids(ids)}"
 
-          #SONAR
+          # SONAR
           conditions = ([conditions] * (ids.size.to_f/MAX_IDS_PER_ORACLE_QUERY).ceil).join(" OR ")
-          #SONAR
+          # /SONAR
 
           conditions << append_conditions(reflection, preload_options)
 
-          #SONAR
+          # SONAR
           associated_records = klass.with_exclusive_scope do
             klass.find(:all, :conditions => [conditions, *ids.in_groups_of(MAX_IDS_PER_ORACLE_QUERY, false)],
                                           :include => options[:include],
@@ -369,37 +369,39 @@ module ActiveRecord
                                           :joins => options[:joins],
                                           :order => options[:order])
           end
-          #SONAR
+          # /SONAR
           set_association_single_records(id_map, reflection.name, associated_records, primary_key)
         end
       end
 
       def find_associated_records(ids, reflection, preload_options)
-        options = reflection.options
-        table_name = reflection.klass.quoted_table_name
-
-        if interface = reflection.options[:as]
-          conditions = "#{reflection.klass.quoted_table_name}.#{connection.quote_column_name "#{interface}_id"} #{in_or_equals_for_ids(ids)} and #{reflection.klass.quoted_table_name}.#{connection.quote_column_name "#{interface}_type"} = '#{self.base_class.sti_name}'"
-        else
-          foreign_key = reflection.primary_key_name
-          conditions = "#{reflection.klass.quoted_table_name}.#{foreign_key} #{in_or_equals_for_ids(ids)}"
-        end
+        # SONAR - iterate over safe_for_oracle_ids
+        associated_records = []
+        ids.each_slice(MAX_IDS_PER_ORACLE_QUERY) do |safe_for_oracle_ids|
+           options = reflection.options
+           table_name = reflection.klass.quoted_table_name
 
-        #SONAR patch for Oracle IN clause with more than 1000 elements
-        conditions = ([conditions] * (ids.size.to_f/MAX_IDS_PER_ORACLE_QUERY).ceil).join(" OR ")
-        #SONAR
+           if interface = reflection.options[:as]
+            conditions = "#{reflection.klass.quoted_table_name}.#{connection.quote_column_name "#{interface}_id"} #{in_or_equals_for_ids(safe_for_oracle_ids)} and #{reflection.klass.quoted_table_name}.#{connection.quote_column_name "#{interface}_type"} = '#{self.base_class.sti_name}'"
+           else
+            foreign_key = reflection.primary_key_name
+            conditions = "#{reflection.klass.quoted_table_name}.#{foreign_key} #{in_or_equals_for_ids(safe_for_oracle_ids)}"
+           end
 
-        conditions << append_conditions(reflection, preload_options)
+           conditions << append_conditions(reflection, preload_options)
 
-        reflection.klass.with_exclusive_scope do
-          reflection.klass.find(:all,
+           reflection.klass.with_exclusive_scope do
+             associated_records += reflection.klass.find(:all,
                               :select => (preload_options[:select] || options[:select] || "#{table_name}.*"),
                               :include => preload_options[:include] || options[:include],
-                              :conditions => [conditions, ids],
+                              :conditions => [conditions, safe_for_oracle_ids],
                               :joins => options[:joins],
                               :group => preload_options[:group] || options[:group],
                               :order => preload_options[:order] || options[:order])
-        end
+           end
+         end
+         associated_records
+        # /SONAR
       end