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

uow: add "bulk_index" param on ParentRecordCommmitOp #271

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions invenio_drafts_resources/services/records/uow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ def __init__(
self,
parent,
indexer_context=None,
bulk_index=True,
):
"""Initialize the parent record commit operation.

:params indexer_context: a dict containing record/draft cls and indexers,
or service. Expected keys: `record_cls, draft_cls, indexer, draft_indexer`.
`None` if indexing disabled.
:params bulk_index: if ``True`` will send to bulk indexing queue. Otherwise will
index synchronously.
"""
super().__init__(parent, indexer=None)
self._indexer_context = indexer_context
Expand All @@ -39,6 +42,7 @@ def __init__(
self._draft_cls = indexer_context["draft_cls"]
self._record_indexer = indexer_context["indexer"]
self._draft_indexer = indexer_context["draft_indexer"]
self._bulk_index = bulk_index

def _get_siblings(self):
"""Get all record and draft versions by parent.
Expand All @@ -64,6 +68,14 @@ def on_post_commit(self, uow):
if self._indexer_context is not None:
records_ids, drafts_ids = self._get_siblings()
if records_ids:
self._record_indexer.bulk_index(records_ids)
if self._bulk_index:
self._record_indexer.bulk_index(records_ids)
else:
for record_id in records_ids:
self._record_indexer.index_by_id(record_id)
if drafts_ids:
self._draft_indexer.bulk_index(drafts_ids)
if self._bulk_index:
self._draft_indexer.bulk_index(drafts_ids)
else:
for draft_id in drafts_ids:
self._draft_indexer.index_by_id(draft_id)
Loading