From ec34753043964df9427224e6aaad96c5f8c951a3 Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Sat, 31 Aug 2024 00:46:02 +0530 Subject: [PATCH] fix: update library v2 search index synchronously (#35367) Discarded components need to be removed from index in sync to make sure that users see the latest updated data. --- openedx/core/djangoapps/content/search/handlers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/content/search/handlers.py b/openedx/core/djangoapps/content/search/handlers.py index ba0e8c1a16..94ac02ea16 100644 --- a/openedx/core/djangoapps/content/search/handlers.py +++ b/openedx/core/djangoapps/content/search/handlers.py @@ -136,7 +136,13 @@ def content_library_updated_handler(**kwargs) -> None: log.error("Received null or incorrect data for event") return - update_content_library_index_docs.delay(str(content_library_data.library_key)) + # Update content library index synchronously to make sure that search index is updated before + # the frontend invalidates/refetches index. + # Currently, this is only required to make sure that removed/discarded components are removed + # from the search index and displayed to user properly. If it becomes a performance bottleneck + # for other update operations other than discard, we can update CONTENT_LIBRARY_UPDATED event + # to include a parameter which can help us decide if the task needs to run sync or async. + update_content_library_index_docs.apply(args=[str(content_library_data.library_key)]) @receiver(CONTENT_OBJECT_TAGS_CHANGED)