Reputation: 181
When using paper_trail (https://github.com/paper-trail-gem/paper_trail), is there a more efficient way to store object_changes? Especially for jsonb columns, a large amount of data is stored in the table as it stores the entire value of the field before and after the change was made, even if the change was one key in a large object.
Right now, when I send it to the view I am using Hashdiff (https://github.com/liufengyun/hashdiff) to find the specific things that were changed, but I have to run this every time a view is loaded, plus there is a large load on the db as the entire field change is stored every time - versions is by far my largest table.
Is there an option of storing the Hashdiff directly in the object_changes and dumping that into the view every time it is loaded? It would make things a lot faster and less load on the db.
Upvotes: 2
Views: 1460
Reputation: 17528
Ashwin and I added this feature in PR 1102, released in 9.2. Here is the changelog entry:
## 9.2.0 (2018-06-09)
### Added
- [#1093](https://github.com/paper-trail-gem/paper_trail/pull/1093) -
`PaperTrail.config.object_changes_adapter` - Expert users can write their own
adapter to control how the changes for each version are stored in the
object_changes column. An example of this implementation using the hashdiff
gem can be found here:
[paper_trail-hashdiff](https://github.com/hashwin/paper_trail-hashdiff)
Upvotes: 3