'How to reduce the number of tracking records when saving on keystroke?
When saving changes to a model in rails, two popular gems to track changes are paper_trail and audited. These gems create records that contain versioning information every time the model is updated.
How can I reduce the number of records created when saving user input as they type?
For example:
- User start filling out an input for the title of a model
- User starts typing "App" then a few second later "le"
- The database now contains two versioning records "App" and "le"
Note: Putting a delay on the user interface (say 250ms before saving) will reduce the number of records, but we will still have a bunch of updates that are really just one.
Solution 1:[1]
I think the best solution would be to skip versioning based on conditions (column, last_updated_at, etc). Then wrap the controller action with the following block.
PaperTrail.request(enabled: false) do
# no versions created
end
Solution
Use different endpoints for the keystroke requests and form submission.
Keystroke Endpoint
Used only by keystroke requests and is wrapped with the code above to skip_versioning
.
Form submission endpoint
Used only when the form is submitted.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |