Skip to content

Dirty tracking refactor #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 20, 2016
Merged

Dirty tracking refactor #211

merged 6 commits into from
Aug 20, 2016

Conversation

samlown
Copy link
Member

@samlown samlown commented Aug 19, 2016

Complete refactor of dirty tracking of CouchRest Model properties. The objective is to fix the issues with nested objects and failing to detect changes in complex models that don't use the Embeddable class. ActiveModel Dirty wasn't designed for this level of complexity, so was falling short.

This dirty tracking proposal uses the Hashdiff gem to compare a cached "raw" hash of attributes, including nested objects. The smallest change is picked out, regardless of the complexity of the underlying data.

The only caveat with the Hashdiff gem is that the comparison results uses a special format that is not comparable to the standard result from ActiveModel. Given that CouchDB is not capable of partial updates, this seems an acceptable tradeoff for reliability. Some methods provided by ActiveModel::Dirty are also no longer available: changes_applied, restore_attributes, previous_changes, and changed_attributes.

Also of note is that comparisons are always performed using "raw" data; the documents that will actually be sent for storage. This makes comparisons simpler and more reliable, but may cause confusion when trying to use the results of a comparison.

If you're worried about the performance of the Hashdiff gem and extra memory requirements, dirty tracking can be disabled either globally, or on a model-level using the disable_dirty_tracking configuration option.

@samlown samlown merged commit dde59dd into couchrest:master Aug 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant