aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-06-20 12:04:08 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-06-20 12:08:47 +0200
commit2d9ebcf3180f5931e4ab6c46fcdc47b01f188861 (patch)
tree4d3e7c2c8d722e0d6fffbc2818c913d822c67409
parent13a0ff98e2108fe6c8fe482114df4619834c347e (diff)
downloadsonarqube-2d9ebcf3180f5931e4ab6c46fcdc47b01f188861.tar.gz
sonarqube-2d9ebcf3180f5931e4ab6c46fcdc47b01f188861.zip
SONAR-2535 The resource viewer displays an error message when there are more than 1'000 violations on a resource
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/config/environment.rb2
-rwxr-xr-xsonar-server/src/main/webapp/WEB-INF/vendor/rails/activerecord/lib/active_record/association_preload.rb44
2 files changed, 24 insertions, 22 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/config/environment.rb b/sonar-server/src/main/webapp/WEB-INF/config/environment.rb
index cf15d6a5a31..2aaca86abb7 100644
--- a/sonar-server/src/main/webapp/WEB-INF/config/environment.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/config/environment.rb
@@ -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'
diff --git a/sonar-server/src/main/webapp/WEB-INF/vendor/rails/activerecord/lib/active_record/association_preload.rb b/sonar-server/src/main/webapp/WEB-INF/vendor/rails/activerecord/lib/active_record/association_preload.rb
index d95e41c0f14..e3802d92568 100755
--- a/sonar-server/src/main/webapp/WEB-INF/vendor/rails/activerecord/lib/active_record/association_preload.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/vendor/rails/activerecord/lib/active_record/association_preload.rb
@@ -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