Avoid N << method calls in #import_without_validations_or_callbacks by chaining #map (is simpler, should be more performant, AFAIK)

This commit is contained in:
Ben Woosley 2010-11-16 23:09:15 -08:00 committed by Zach Dennis
parent fff00af942
commit 2ada56f858

View file

@ -264,12 +264,11 @@ class ActiveRecord::Base
insert_statements, values = [], [] insert_statements, values = [], []
number_inserted = 0 number_inserted = 0
array_of_attributes.each do |arr| array_of_attributes.each do |arr|
my_values = [] my_values = arr.each_with_index.map do |val,j|
arr.each_with_index do |val,j|
if !sequence_name.blank? && column_names[j] == primary_key && val.nil? if !sequence_name.blank? && column_names[j] == primary_key && val.nil?
my_values << connection.next_value_for_sequence(sequence_name) connection.next_value_for_sequence(sequence_name)
else else
my_values << connection.quote( val, columns[j] ) connection.quote( val, columns[j] )
end end
end end
insert_statements << "INSERT INTO #{quoted_table_name} #{columns_sql} VALUES(" + my_values.join( ',' ) + ")" insert_statements << "INSERT INTO #{quoted_table_name} #{columns_sql} VALUES(" + my_values.join( ',' ) + ")"