From d426306fbd632cc084830694bdb097a1dcf91de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Tue, 19 Mar 2024 14:25:01 -0300 Subject: [PATCH] fix: merging changes from upstream PR --- openedx/core/djangoapps/content/search/api.py | 14 ++++++++------ .../core/djangoapps/content/search/documents.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/openedx/core/djangoapps/content/search/api.py b/openedx/core/djangoapps/content/search/api.py index 273e1e3a4e5f..fb91ae2ef46a 100644 --- a/openedx/core/djangoapps/content/search/api.py +++ b/openedx/core/djangoapps/content/search/api.py @@ -88,8 +88,8 @@ def _get_meilisearch_client(): return _MEILI_CLIENT # Connect to Meilisearch - if not settings.MEILISEARCH_URL: - raise RuntimeError("MEILISEARCH_URL is not set - search functionality disabled.") + if not settings.MEILISEARCH_ENABLED: + raise RuntimeError("MEILISEARCH_ENABLED is not set - search functionality disabled.") _MEILI_CLIENT = meilisearch.Client(settings.MEILISEARCH_URL, settings.MEILISEARCH_API_KEY) try: @@ -252,8 +252,9 @@ def nop(_message): doc = searchable_doc_for_library_block(metadata) docs.append(doc) num_blocks_done += 1 - # Add all the docs in this library at once (usually faster than adding one at a time): - _wait_for_meili_task(client.index(temp_index_name).add_documents(docs)) + if docs: + # Add all the docs in this library at once (usually faster than adding one at a time): + _wait_for_meili_task(client.index(temp_index_name).add_documents(docs)) num_contexts_done += 1 ############## Courses ############## @@ -272,8 +273,9 @@ def add_with_children(block): _recurse_children(course, add_with_children) - # Add all the docs in this course at once (usually faster than adding one at a time): - _wait_for_meili_task(client.index(temp_index_name).add_documents(docs)) + if docs: + # Add all the docs in this course at once (usually faster than adding one at a time): + _wait_for_meili_task(client.index(temp_index_name).add_documents(docs)) num_contexts_done += 1 num_blocks_done += len(docs) diff --git a/openedx/core/djangoapps/content/search/documents.py b/openedx/core/djangoapps/content/search/documents.py index 3a3c57db288e..02f30545323b 100644 --- a/openedx/core/djangoapps/content/search/documents.py +++ b/openedx/core/djangoapps/content/search/documents.py @@ -81,7 +81,7 @@ class implementation returns only: {"content": {"display_name": "..."}, "content_type": "..."} """ block_data = { - Fields.id: _meili_id_from_opaque_key(block.usage_key), + Fields.id: meili_id_from_opaque_key(block.usage_key), Fields.usage_key: str(block.usage_key), Fields.block_id: str(block.usage_key.block_id), Fields.display_name: xblock_api.get_block_display_name(block),