aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/attribute_mutation_tracker.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #32498 from eugeneius/mutation_tracker_merge_changesRyuta Kamizono2018-04-101-1/+1
|\ | | | | Prevent changes_to_save from mutating attributes
| * Prevent changes_to_save from mutating attributesEugene Kenny2018-04-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | When an array of hashes is added to a `HashWithIndifferentAccess`, the hashes are replaced with HWIAs by mutating the array in place. If an attribute's value is an array of hashes, `changes_to_save` will convert it to an array of HWIAs as a side-effect of adding it to the changes hash. Using `merge!` instead of `[]=` fixes the problem, as `merge!` copies any array values in the provided hash instead of mutating them.
* | Avoid generating full changes hash on every saveEugene Kenny2018-04-081-0/+8
|/ | | | | | | | | | `changed_attribute_names_to_save` is called in `keys_for_partial_write`, which is called on every save when partial writes are enabled. We can avoid generating the full changes hash by asking the mutation tracker for just the names of the changed attributes. At minimum this saves one array allocation per attribute, but will also avoid calling `Attribute#original_value` which is expensive for serialized attributes.
* Revert "PERF: Recover `changes_applied` performance (#31698)"Sean Griffin2018-03-061-4/+3
| | | | This reverts commit a19e91f0fab13cca61acdb1f33e27be2323b9786.
* Rails 6 requires Ruby 2.3+Jeremy Daer2018-02-171-6/+1
|
* PERF: Recover `changes_applied` performance (#31698)Ryuta Kamizono2018-01-221-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | #30985 caused `object.save` performance regression since calling `changes` in `changes_applied` is very slow. We don't need to call the expensive method in `changes_applied` as long as `@attributes` is tracked by mutation tracker. https://gist.github.com/kamipo/1a9f4f3891803b914fc72ede98268aa2 Before: ``` Warming up -------------------------------------- create_string_columns 73.000 i/100ms Calculating ------------------------------------- create_string_columns 722.256 (± 5.8%) i/s - 3.650k in 5.073031s ``` After: ``` Warming up -------------------------------------- create_string_columns 96.000 i/100ms Calculating ------------------------------------- create_string_columns 950.224 (± 7.7%) i/s - 4.800k in 5.084837s ```
* Add missing require "active_support/core_ext/hash/indifferent_access"Ryuta Kamizono2017-11-101-0/+2
| | | | https://travis-ci.org/rails/rails/jobs/300163454#L2236
* Move Attribute and AttributeSet to ActiveModelLisa Ugray2017-11-091-0/+114
Use these to back the attributes API. Stop automatically including ActiveModel::Dirty in ActiveModel::Attributes, and make it optional.