Skip to content
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

Merged
merged 4 commits into from
Jun 9, 2023

Conversation

tagirahmad
Copy link
Contributor

@tagirahmad tagirahmad commented Apr 25, 2023

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 and include_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

  • I've added tests for this change
  • I've added a Changelog entry
  • I've updated a documentation (Readme)

Copy link
Owner

@palkan palkan left a 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).

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
Copy link
Owner

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.

@tagirahmad
Copy link
Contributor Author

Is it ok, @palkan?

@palkan
Copy link
Owner

palkan commented Jun 8, 2023

LGTM 👍 Let's add a changelog entry and update the docs.

@palkan palkan merged commit acf61f9 into palkan:master Jun 9, 2023
13 checks passed
@palkan
Copy link
Owner

palkan commented Jun 9, 2023

Thanks!

miharekar added a commit to miharekar/logidze that referenced this pull request Mar 2, 2024
palkan pushed a commit that referenced this pull request Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants