Skip to content

Commit

Permalink
test: delete documents that were never published on discard
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Aug 14, 2024
1 parent a6ddaa5 commit 508f6b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions openedx/core/djangoapps/content/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions openedx/core/djangoapps/content/search/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions openedx/core/djangoapps/content/search/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 508f6b7

Please sign in to comment.