Merge pull request #726 from airblade/optimize_rollback_reload

Optimize post-rollback association reset
This commit is contained in:
Jared Beck 2016-03-06 16:10:08 -05:00
commit 16a07c2f50
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