diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-04-09 10:27:45 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-09 10:27:45 +0900 |
commit | bc9fb9cf8b5dbe8ecf399ffd5d48d84bdb96a9db (patch) | |
tree | ee77eb11f5cc7ff60a1096801dc89b06b456c770 | |
parent | d729bc748811339c7e536f4ca98e91801e14c6f4 (diff) | |
parent | b9e1c0c4d7c67a65c2ea63e7f0925f4d0da306aa (diff) | |
download | rails-bc9fb9cf8b5dbe8ecf399ffd5d48d84bdb96a9db.tar.gz rails-bc9fb9cf8b5dbe8ecf399ffd5d48d84bdb96a9db.tar.bz2 rails-bc9fb9cf8b5dbe8ecf399ffd5d48d84bdb96a9db.zip |
Merge pull request #32497 from eugeneius/mutation_tracker_changed_attribute_names
Avoid generating full changes hash on every save
-rw-r--r-- | activemodel/lib/active_model/attribute_mutation_tracker.rb | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/dirty.rb | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/attribute_mutation_tracker.rb b/activemodel/lib/active_model/attribute_mutation_tracker.rb index 493be5bb88..82d90664c0 100644 --- a/activemodel/lib/active_model/attribute_mutation_tracker.rb +++ b/activemodel/lib/active_model/attribute_mutation_tracker.rb @@ -11,6 +11,10 @@ module ActiveModel @forced_changes = Set.new end + def changed_attribute_names + attr_names.select { |attr_name| changed?(attr_name) } + end + def changed_values attr_names.each_with_object({}.with_indifferent_access) do |attr_name, result| if changed?(attr_name) @@ -76,6 +80,10 @@ module ActiveModel class NullMutationTracker # :nodoc: include Singleton + def changed_attribute_names(*) + [] + end + def changed_values(*) {} end diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index 3de6fe566d..7224f970e0 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -114,7 +114,7 @@ module ActiveRecord # Alias for +changed+ def changed_attribute_names_to_save - changes_to_save.keys + mutations_from_database.changed_attribute_names end # Alias for +changed_attributes+ |