Skip to content

Commit

Permalink
uow: add "bulk_index" param on ParentRecordCommmitOp
Browse files Browse the repository at this point in the history
  • Loading branch information
slint authored and lnielsen committed Dec 11, 2023
1 parent de8ccd8 commit 419e0bb
Showing 1 changed file with 14 additions and 2 deletions.
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)

0 comments on commit 419e0bb

Please sign in to comment.