1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00

Optimize post-rollback association reset

[Fixes #715]
This commit is contained in:
Jared Beck 2016-03-06 14:05:21 -05:00
parent 534aa778fb
commit 6fd232df60
3 changed files with 10 additions and 2 deletions

View file

@ -22,6 +22,8 @@
### Fixed
- [#715](https://github.com/airblade/paper_trail/issues/715) -
Optimize post-rollback association reset.
- [#701](https://github.com/airblade/paper_trail/pull/701) /
[#699](https://github.com/airblade/paper_trail/issues/699) -
Cleaning old versions explicitly preserves the most recent

View file

@ -195,9 +195,11 @@ module PaperTrail
end
# Invoked after rollbacks to ensure versions records are not created
# for changes that never actually took place
# for changes that never actually took place.
# Optimization: Use lazy `reset` instead of eager `reload` because, in
# many use cases, the association will not be used.
def clear_rolled_back_versions
send(self.class.versions_association_name).reload
send(self.class.versions_association_name).reset
end
# Returns the object (not a Version) as it was at the given timestamp.

View file

@ -110,6 +110,10 @@ describe Widget, type: :model do
expect(changeset.fetch("name", [])).to_not include(rolled_back_name)
end
end
it "has not yet loaded the assocation" do
expect(widget.versions).to_not be_loaded
end
end
end