From 8fe50a7e3678c9bc27b1178935c77e9413451a51 Mon Sep 17 00:00:00 2001 From: Braden MacDonald Date: Tue, 17 Sep 2024 12:37:02 -0700 Subject: [PATCH 1/2] feat: when changing a v2 library block, update search index synchronously --- openedx/core/djangoapps/content/search/handlers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/content/search/handlers.py b/openedx/core/djangoapps/content/search/handlers.py index 1605f8ebfd58..43e6d2912935 100644 --- a/openedx/core/djangoapps/content/search/handlers.py +++ b/openedx/core/djangoapps/content/search/handlers.py @@ -124,7 +124,9 @@ def library_block_updated_handler(**kwargs) -> None: log.error("Received null or incorrect data for event") return - upsert_library_block_index_doc.delay(str(library_block_data.usage_key)) + # Update content library index synchronously to make sure that search index is updated before + # the frontend invalidates/refetches results. This is only a single document update so is very fast. + upsert_library_block_index_doc.apply(args=[str(library_block_data.usage_key)]) @receiver(LIBRARY_BLOCK_DELETED) From 4e2027e7a68c00294abb8a2b2260b6e1fa33a42b Mon Sep 17 00:00:00 2001 From: Braden MacDonald Date: Wed, 18 Sep 2024 09:34:31 -0700 Subject: [PATCH 2/2] feat: when deleting a v2 library block, update search index synchronously --- openedx/core/djangoapps/content/search/handlers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/content/search/handlers.py b/openedx/core/djangoapps/content/search/handlers.py index 43e6d2912935..f50dead8474a 100644 --- a/openedx/core/djangoapps/content/search/handlers.py +++ b/openedx/core/djangoapps/content/search/handlers.py @@ -140,7 +140,9 @@ def library_block_deleted(**kwargs) -> None: log.error("Received null or incorrect data for event") return - delete_library_block_index_doc.delay(str(library_block_data.usage_key)) + # Update content library index synchronously to make sure that search index is updated before + # the frontend invalidates/refetches results. This is only a single document update so is very fast. + delete_library_block_index_doc.apply(args=[str(library_block_data.usage_key)]) @receiver(CONTENT_LIBRARY_UPDATED)