diff --git a/openedx/core/djangoapps/content/search/api.py b/openedx/core/djangoapps/content/search/api.py index bad46dab91a6..cc80d36cbd49 100644 --- a/openedx/core/djangoapps/content/search/api.py +++ b/openedx/core/djangoapps/content/search/api.py @@ -474,7 +474,7 @@ def delete_all_draft_docs_for_library(library_key: LibraryLocatorV2) -> None: current_rebuild_index_name = _get_running_rebuild_index_name() client = _get_meilisearch_client() # Delete all documents where last_published is null i.e. never published before. - filter = [ + delete_filter = [ f'{Fields.context_key}="{library_key}"', # inner arrays are connected by an OR [f'{Fields.last_published} IS EMPTY', f'{Fields.last_published} IS NULL'], @@ -483,8 +483,8 @@ def delete_all_draft_docs_for_library(library_key: LibraryLocatorV2) -> None: tasks = [] if current_rebuild_index_name: # If there is a rebuild in progress, the documents will also be deleted from the new index. - tasks.append(client.index(current_rebuild_index_name).delete_documents(filter=filter)) - tasks.append(client.index(STUDIO_INDEX_NAME).delete_documents(filter=filter)) + tasks.append(client.index(current_rebuild_index_name).delete_documents(filter=delete_filter)) + tasks.append(client.index(STUDIO_INDEX_NAME).delete_documents(filter=delete_filter)) _wait_for_meili_tasks(tasks) diff --git a/openedx/core/djangoapps/content/search/handlers.py b/openedx/core/djangoapps/content/search/handlers.py index 02b2e66c47df..ba0e8c1a1680 100644 --- a/openedx/core/djangoapps/content/search/handlers.py +++ b/openedx/core/djangoapps/content/search/handlers.py @@ -136,8 +136,7 @@ def content_library_updated_handler(**kwargs) -> None: log.error("Received null or incorrect data for event") return - if content_library_data.update_blocks: - update_content_library_index_docs.delay(str(content_library_data.library_key)) + update_content_library_index_docs.delay(str(content_library_data.library_key)) @receiver(CONTENT_OBJECT_TAGS_CHANGED) diff --git a/openedx/core/djangoapps/content/search/tests/test_api.py b/openedx/core/djangoapps/content/search/tests/test_api.py index 9dcdfb76b4a6..e8616cee60a8 100644 --- a/openedx/core/djangoapps/content/search/tests/test_api.py +++ b/openedx/core/djangoapps/content/search/tests/test_api.py @@ -388,3 +388,18 @@ def test_index_content_library_metadata(self, mock_meilisearch): mock_meilisearch.return_value.index.return_value.update_documents.assert_called_once_with( [self.doc_problem1, self.doc_problem2] ) + + @override_settings(MEILISEARCH_ENABLED=True) + def test_delete_all_drafts(self, mock_meilisearch): + """ + Test deleting all draft documents from the index. + """ + api.delete_all_draft_docs_for_library(self.library.key) + + delete_filter = [ + f'context_key="{self.library.key}"', + ['last_published IS EMPTY', 'last_published IS NULL'], + ] + mock_meilisearch.return_value.index.return_value.delete_documents.assert_called_once_with( + filter=delete_filter + )