-
Notifications
You must be signed in to change notification settings - Fork 75
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
Add retrieving list of versions support #238
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
The implementation looks good API-wise; now we need to focus on performance (see the comment).
lib/logidze/model.rb
Outdated
versions_meta = reverse ? log_data.versions.reverse : log_data.versions | ||
versions_meta = versions_meta.reject { _1.version == log_data.version } unless include_self | ||
|
||
versions_meta.map { at(version: _1.version) }.to_enum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We wanted this method to return an enumerator to avoid expensive calculation and object creation of generating all versions, i.e., when I call record.logidze_versions.take(2)
I only call #at
twice. Right how, we create an array of all version first—this is not optimal.
We can add a test to check that we don't create a record per version by adding an after_initialize
callback and increment some counter within it.
Is it ok, @palkan? |
LGTM 👍 Let's add a changelog entry and update the docs. |
Thanks! |
It was implemented as such in palkan#238
It was implemented as such in #238
What is the purpose of this pull request?
Add retrieving list of versions support
What changes did you make? (overview)
Added
#logidze_versions
method which retrieves list of versions of model depending on options provided (reverse
andinclude_self
If
reverse
is provided, reversed Enumerator will be returned.If
include_self
is provided, the list will contain also current version of the model.Is there anything you'd like reviewers to focus on?
Checklist