|
18 | 18 | from meilisearch.errors import MeilisearchApiError, MeilisearchError |
19 | 19 | from meilisearch.models.task import TaskInfo |
20 | 20 | from opaque_keys.edx.keys import UsageKey |
21 | | -from opaque_keys.edx.locator import LibraryContainerLocator, LibraryLocatorV2, LibraryCollectionLocator |
| 21 | +from opaque_keys.edx.locator import ( |
| 22 | + LibraryCollectionLocator, |
| 23 | + LibraryContainerLocator, |
| 24 | + LibraryLocatorV2, |
| 25 | +) |
22 | 26 | from openedx_learning.api import authoring as authoring_api |
23 | 27 | from common.djangoapps.student.roles import GlobalStaff |
24 | 28 | from rest_framework.request import Request |
@@ -461,8 +465,9 @@ def index_collection_batch(batch, num_done, library_key) -> int: |
461 | 465 | docs = [] |
462 | 466 | for collection in batch: |
463 | 467 | try: |
464 | | - doc = searchable_doc_for_collection(library_key, collection.key, collection=collection) |
465 | | - doc.update(searchable_doc_tags_for_collection(library_key, collection.key)) |
| 468 | + collection_key = lib_api.library_collection_locator(library_key, collection.key) |
| 469 | + doc = searchable_doc_for_collection(collection_key, collection=collection) |
| 470 | + doc.update(searchable_doc_tags_for_collection(collection_key)) |
466 | 471 | docs.append(doc) |
467 | 472 | except Exception as err: # pylint: disable=broad-except |
468 | 473 | status_cb(f"Error indexing collection {collection}: {err}") |
@@ -703,13 +708,13 @@ def _get_document_from_index(document_id: str) -> dict: |
703 | 708 | return document |
704 | 709 |
|
705 | 710 |
|
706 | | -def upsert_library_collection_index_doc(library_key: LibraryLocatorV2, collection_key: str) -> None: |
| 711 | +def upsert_library_collection_index_doc(collection_key: LibraryCollectionLocator) -> None: |
707 | 712 | """ |
708 | 713 | Creates, updates, or deletes the document for the given Library Collection in the search index. |
709 | 714 |
|
710 | 715 | If the Collection is not found or disabled (i.e. soft-deleted), then delete it from the search index. |
711 | 716 | """ |
712 | | - doc = searchable_doc_for_collection(library_key, collection_key) |
| 717 | + doc = searchable_doc_for_collection(collection_key) |
713 | 718 | update_components = False |
714 | 719 |
|
715 | 720 | # Soft-deleted/disabled collections are removed from the index |
@@ -739,21 +744,24 @@ def upsert_library_collection_index_doc(library_key: LibraryLocatorV2, collectio |
739 | 744 | if update_components: |
740 | 745 | from .tasks import update_library_components_collections as update_task |
741 | 746 |
|
742 | | - update_task.delay(str(library_key), collection_key) |
| 747 | + update_task.delay(str(collection_key)) |
743 | 748 |
|
744 | 749 |
|
745 | 750 | def update_library_components_collections( |
746 | | - library_key: LibraryLocatorV2, |
747 | | - collection_key: str, |
| 751 | + collection_key: LibraryCollectionLocator, |
748 | 752 | batch_size: int = 1000, |
749 | 753 | ) -> None: |
750 | 754 | """ |
751 | 755 | Updates the "collections" field for all components associated with a given Library Collection. |
752 | 756 |
|
753 | 757 | Because there may be a lot of components, we send these updates to Meilisearch in batches. |
754 | 758 | """ |
| 759 | + library_key = collection_key.library_key |
755 | 760 | library = lib_api.get_library(library_key) |
756 | | - components = authoring_api.get_collection_components(library.learning_package_id, collection_key) |
| 761 | + components = authoring_api.get_collection_components( |
| 762 | + library.learning_package_id, |
| 763 | + collection_key.collection_id, |
| 764 | + ) |
757 | 765 |
|
758 | 766 | paginator = Paginator(components, batch_size) |
759 | 767 | for page in paginator.page_range: |
@@ -829,12 +837,12 @@ def upsert_block_collections_index_docs(usage_key: UsageKey): |
829 | 837 | _update_index_docs([doc]) |
830 | 838 |
|
831 | 839 |
|
832 | | -def upsert_collection_tags_index_docs(collection_usage_key: LibraryCollectionLocator): |
| 840 | +def upsert_collection_tags_index_docs(collection_key: LibraryCollectionLocator): |
833 | 841 | """ |
834 | 842 | Updates the tags data in documents for the given library collection |
835 | 843 | """ |
836 | 844 |
|
837 | | - doc = searchable_doc_tags_for_collection(collection_usage_key.library_key, collection_usage_key.collection_id) |
| 845 | + doc = searchable_doc_tags_for_collection(collection_key) |
838 | 846 | _update_index_docs([doc]) |
839 | 847 |
|
840 | 848 |
|
|
0 commit comments