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

versions: calculate record's active versions #274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anikachurilova
Copy link
Contributor

@anikachurilova anikachurilova marked this pull request as ready for review August 5, 2024 10:02
@anikachurilova anikachurilova force-pushed the Search-result-1-more-version-exists-wrongly-added branch from fbba67f to 9542bb8 Compare August 14, 2024 08:50
Copy link
Member

@ptamarit ptamarit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a test for versions_count?

def versions_count(self):
"""Get number of record's active versions"""
records = list(
self.get_record_versions(parent_id=self.parent.id, include_deleted=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we reuse get_records_by_parent with with_deleted=False, ids_only=True?

This would fix the tests which are failing due to the import from invenio_rdm_records which we cannot do in invenio-drafts-resources.
Not sure what is the difference between is_deleted and deletion_status in the model.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After checking, I can confirm that we need to use the deletion_status and not is_deleted=False as is_deleted is checking for empty json (see here)

You are right tho, that we can not import invenio_rdm_records... I could hardcode the value "P" of the RecordDeletionStatusEnum.PUBLISHED..

Copy link
Contributor

@ntarocco ntarocco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After checking, we should explore a different implementation.

I would add the property count inside the versions system field, and calculate the number of versions there.
The query should exclude both records mark as deleted (RecordDeletionStatusEnum.PUBLISHED.value) and the soft deleted (is_deleted=True).

However, there are a couple of issues:

  1. RecordDeletionStatusEnum.PUBLISHED.value is in rdm-records and cannot be imported here. Does it make sent to move some of that code here? Or in records-resources?
  2. the query should be performant, maybe cached, to avoid multiple calculations and performance hits. However, it is not straightforward to understand when invalidating the cache.

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.

3 participants