-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
collections: added task to compute num of records
* added task to compute number of records for all the collections * added "collection_id" parameter to record search * added service methods to read collections (many, all) * added tests * collections: refactor 'resolve' to 'read' * collections: rename 'search_records' method * collections: update read method signature
- Loading branch information
1 parent
970aa7b
commit 9e56947
Showing
10 changed files
with
304 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# Invenio-RDM-Records is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Collections celery tasks.""" | ||
|
||
from celery import shared_task | ||
from flask import current_app | ||
from invenio_access.permissions import system_identity | ||
|
||
from invenio_rdm_records.proxies import current_rdm_records | ||
|
||
|
||
@shared_task(ignore_result=True) | ||
def update_collections_size(): | ||
"""Calculate and update the size of all the collections.""" | ||
collections_service = current_rdm_records.collections_service | ||
res = collections_service.read_all(system_identity, depth=0) | ||
for citem in res: | ||
try: | ||
collection = citem._collection | ||
res = collections_service.search_collection_records( | ||
system_identity, collection | ||
) | ||
collections_service.update( | ||
system_identity, collection, data={"num_records": res.total} | ||
) | ||
except Exception as e: | ||
current_app.logger.exception(str(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.