From e126078a0e013acfe0a397a8dad33b2c9de78732 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 6 Mar 2018 15:09:34 -0700 Subject: Don't call changes in `changes_applied` unless required This is an alternate implementation of #31698. That PR makes assumptions that I do not want in the code base. We can fix the performance regression with a much simpler patch. --- activemodel/lib/active_model/dirty.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index d2ebd18107..eaf8dfb223 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -142,7 +142,9 @@ module ActiveModel end def changes_applied # :nodoc: - @previously_changed = changes + unless defined?(@attributes) + @previously_changed = changes + end @mutations_before_last_save = mutations_from_database @attributes_changed_by_setter = ActiveSupport::HashWithIndifferentAccess.new forget_attribute_assignments -- cgit v1.2.3