Skip to content

Commit c3e1cf5

Browse files
committed
Check for default function before attribute changes for partial inserts
We're limiting the attributes being used for INSERTs to those without a default function and no changes. But we can first check for the presence of a default function before checking for changes. That's because the default function will be stored in the schema cache and amounts to a hash fetch in column_for_attribute, while checking for changes potentially calls user code when using the Active Record Attributes API.
1 parent aa0c418 commit c3e1cf5

File tree

1 file changed

+3
-1
lines changed
  • activerecord/lib/active_record/attribute_methods

1 file changed

+3
-1
lines changed

activerecord/lib/active_record/attribute_methods/dirty.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ def attribute_names_for_partial_inserts
233233
changed_attribute_names_to_save
234234
else
235235
attribute_names.reject do |attr_name|
236-
!attribute_changed?(attr_name) && column_for_attribute(attr_name).default_function
236+
if column_for_attribute(attr_name).default_function
237+
!attribute_changed?(attr_name)
238+
end
237239
end
238240
end
239241
end

0 commit comments

Comments
 (0)