From b81215990265f02b841e5367f6e0bbd172e0f225 Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Fri, 13 Dec 2024 10:56:41 +0530 Subject: [PATCH] fix: use content object associations changed event to update collections on restore --- openedx/core/djangoapps/content/search/documents.py | 2 -- openedx/core/djangoapps/content_libraries/api.py | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/content/search/documents.py b/openedx/core/djangoapps/content/search/documents.py index 245d9db8af1..40fe4529272 100644 --- a/openedx/core/djangoapps/content/search/documents.py +++ b/openedx/core/djangoapps/content/search/documents.py @@ -401,8 +401,6 @@ def searchable_doc_for_library_block(xblock_metadata: lib_api.LibraryXBlockMetad # Add the breadcrumbs. In v2 libraries, the library itself is not a "parent" of the XBlocks so we add it here: doc[Fields.breadcrumbs] = [{"display_name": library_name}] - # Add collections data to index if this block is part of any collection - doc.update(_collections_for_content_object(xblock_metadata.usage_key)) return doc diff --git a/openedx/core/djangoapps/content_libraries/api.py b/openedx/core/djangoapps/content_libraries/api.py index 9f8d81401b4..c51c707fc47 100644 --- a/openedx/core/djangoapps/content_libraries/api.py +++ b/openedx/core/djangoapps/content_libraries/api.py @@ -1151,6 +1151,14 @@ def restore_library_block(usage_key): ) ) + # Add tags and collections back to index + CONTENT_OBJECT_ASSOCIATIONS_CHANGED.send_event( + content_object=ContentObjectChangedData( + object_id=str(usage_key), + changes=["collections", "tags"], + ), + ) + # For each collection, trigger LIBRARY_COLLECTION_UPDATED signal and set background=True to trigger # collection indexing asynchronously. #