Permalink
Browse files

Performance boost for AR#create

  • Loading branch information...
1 parent 046c22c commit b326faef0936e5a845d1f6eb9ed2200babfd05f8 @miloops miloops committed Jul 20, 2009
Showing with 4 additions and 3 deletions.
  1. +4 −3 activerecord/lib/active_record/base.rb
@@ -2933,10 +2933,12 @@ def create
self.id = connection.next_sequence_value(self.class.sequence_name)
end
- new_id = if arel_attributes_values.empty?
+ attributes_values = arel_attributes_values
+
+ new_id = if attributes_values.empty?
arel_table.insert connection.empty_insert_statement_value
else
- arel_table.insert arel_attributes_values
+ arel_table.insert attributes_values
end
self.id ||= new_id
@@ -3036,7 +3038,6 @@ def attributes_with_quotes(include_primary_key = true, include_readonly_attribut
# an Arel insert/update method.
def arel_attributes_values(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
attrs = {}
- connection = self.class.connection
attribute_names.each do |name|
if (column = column_for_attribute(name)) && (include_primary_key || !column.primary)
value = read_attribute(name)

0 comments on commit b326fae

Please sign in to comment.