aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan Thacker-Smith <Dylan.Smith@shopify.com>2017-08-29 20:12:10 -0400
committerDylan Thacker-Smith <Dylan.Smith@shopify.com>2017-08-30 10:46:01 -0400
commitc342d58446defad94f26c067b19003c9941f2470 (patch)
tree72f9899262e5e75c42b32822d2b528eb9db03f48
parent5c2c8d8cfd7fc8ec58c906e192c1d4f305bf7095 (diff)
downloadrails-c342d58446defad94f26c067b19003c9941f2470.tar.gz
rails-c342d58446defad94f26c067b19003c9941f2470.tar.bz2
rails-c342d58446defad94f26c067b19003c9941f2470.zip
activerecord: Remove a redundant mutation tracker
The extra mutation tracker was needed in Rails 5.1 to preserve the old behaviour of `changes`, but now there is no difference between `changes` and `changes_to_save`, so `@mutation_tracker` can be removed.
-rw-r--r--activerecord/lib/active_record/attribute_methods/dirty.rb32
-rw-r--r--activerecord/lib/active_record/persistence.rb2
2 files changed, 10 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb
index 4f957ac3ca..06598439d8 100644
--- a/activerecord/lib/active_record/attribute_methods/dirty.rb
+++ b/activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -34,7 +34,7 @@ module ActiveRecord
def reload(*)
super.tap do
@mutations_before_last_save = nil
- clear_mutation_trackers
+ @mutations_from_database = nil
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
end
end
@@ -44,22 +44,21 @@ module ActiveRecord
@attributes = self.class._default_attributes.map do |attr|
attr.with_value_from_user(@attributes.fetch_value(attr.name))
end
- clear_mutation_trackers
+ @mutations_from_database = nil
end
def changes_applied # :nodoc:
- @mutations_before_last_save = mutation_tracker
- @mutations_from_database = AttributeMutationTracker.new(@attributes)
+ @mutations_before_last_save = mutations_from_database
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
forget_attribute_assignments
- clear_mutation_trackers
+ @mutations_from_database = nil
end
def clear_changes_information # :nodoc:
@mutations_before_last_save = nil
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
forget_attribute_assignments
- clear_mutation_trackers
+ @mutations_from_database = nil
end
def clear_attribute_changes(attr_names) # :nodoc:
@@ -75,7 +74,7 @@ module ActiveRecord
if defined?(@cached_changed_attributes)
@cached_changed_attributes
else
- super.reverse_merge(mutation_tracker.changed_values).freeze
+ super.reverse_merge(mutations_from_database.changed_values).freeze
end
end
@@ -90,7 +89,7 @@ module ActiveRecord
end
def attribute_changed_in_place?(attr_name) # :nodoc:
- mutation_tracker.changed_in_place?(attr_name)
+ mutations_from_database.changed_in_place?(attr_name)
end
# Did this attribute change when we last saved? This method can be invoked
@@ -183,26 +182,18 @@ module ActiveRecord
result
end
- def mutation_tracker
- unless defined?(@mutation_tracker)
- @mutation_tracker = nil
- end
- @mutation_tracker ||= AttributeMutationTracker.new(@attributes)
- end
-
def mutations_from_database
unless defined?(@mutations_from_database)
@mutations_from_database = nil
end
- @mutations_from_database ||= mutation_tracker
+ @mutations_from_database ||= AttributeMutationTracker.new(@attributes)
end
def changes_include?(attr_name)
- super || mutation_tracker.changed?(attr_name)
+ super || mutations_from_database.changed?(attr_name)
end
def clear_attribute_change(attr_name)
- mutation_tracker.forget_change(attr_name)
mutations_from_database.forget_change(attr_name)
end
@@ -227,11 +218,6 @@ module ActiveRecord
@attributes = @attributes.map(&:forgetting_assignment)
end
- def clear_mutation_trackers
- @mutation_tracker = nil
- @mutations_from_database = nil
- end
-
def mutations_before_last_save
@mutations_before_last_save ||= NullMutationTracker.instance
end
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index fbbf9082cc..b28f6e96a9 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -228,7 +228,7 @@ module ActiveRecord
def becomes(klass)
became = klass.new
became.instance_variable_set("@attributes", @attributes)
- became.instance_variable_set("@mutation_tracker", @mutation_tracker) if defined?(@mutation_tracker)
+ became.instance_variable_set("@mutations_from_database", @mutations_from_database) if defined?(@mutations_from_database)
became.instance_variable_set("@changed_attributes", attributes_changed_by_setter)
became.instance_variable_set("@new_record", new_record?)
became.instance_variable_set("@destroyed", destroyed?)