Skip to content

Commit aeac4fc

Browse files
committed
Avoid reading id twice in AR::Core#hash
This can be a very hot method so we should avoid reading id twice. This restores that optimization we were using before introducing composite primary keys.
1 parent f86f52a commit aeac4fc

File tree

1 file changed

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

1 file changed

+1
-1
lines changed

activerecord/lib/active_record/core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def ==(comparison_object)
611611
def hash
612612
id = self.id
613613

614-
if primary_key_values_present?
614+
if self.class.composite_primary_key? ? primary_key_values_present? : id
615615
self.class.hash ^ id.hash
616616
else
617617
super

0 commit comments

Comments
 (0)