From e23588b50050cd3c934c76f8608d148f23d2874b Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Thu, 10 Oct 2024 12:53:27 +0530 Subject: [PATCH] fix: use lazy field to control collection update task --- .../djangoapps/content/search/handlers.py | 20 ++++++++++++------- .../core/djangoapps/content_libraries/api.py | 6 +----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/openedx/core/djangoapps/content/search/handlers.py b/openedx/core/djangoapps/content/search/handlers.py index 085387d336b1..46b015367a0d 100644 --- a/openedx/core/djangoapps/content/search/handlers.py +++ b/openedx/core/djangoapps/content/search/handlers.py @@ -179,13 +179,19 @@ def library_collection_updated_handler(**kwargs) -> None: log.error("Received null or incorrect data for event") return - # Update collection index synchronously to make sure that search index is updated before - # the frontend invalidates/refetches index. - # See content_library_updated_handler for more details. - update_library_collection_index_doc.apply(args=[ - str(library_collection.library_key), - library_collection.collection_key, - ]) + if library_collection.lazy: + update_library_collection_index_doc.delay( + str(library_collection.library_key), + library_collection.collection_key, + ) + else: + # Update collection index synchronously to make sure that search index is updated before + # the frontend invalidates/refetches index. + # See content_library_updated_handler for more details. + update_library_collection_index_doc.apply(args=[ + str(library_collection.library_key), + library_collection.collection_key, + ]) @receiver(CONTENT_OBJECT_ASSOCIATIONS_CHANGED) diff --git a/openedx/core/djangoapps/content_libraries/api.py b/openedx/core/djangoapps/content_libraries/api.py index 07d07222234f..51d8d0c6e47e 100644 --- a/openedx/core/djangoapps/content_libraries/api.py +++ b/openedx/core/djangoapps/content_libraries/api.py @@ -1287,17 +1287,13 @@ def set_library_component_collections( key__in=collection_keys ) - affected_collections = authoring_api.set_collections( + authoring_api.set_collections( content_library.learning_package_id, component, collection_qs, created_by=created_by, ) - from ..content.search.tasks import update_library_collection_index_doc - for collection in affected_collections: - update_library_collection_index_doc.delay(str(library_key), collection.key) - return component