Skip to content

Commit 892caa8

Browse files
committed
feat: add optional Container object argument
to get_container + get_container_children API methods, to avoid re-fetching this data during search indexing.
1 parent 47a920d commit 892caa8

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

openedx/core/djangoapps/content_libraries/api/containers.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,18 @@ def get_container_from_key(container_key: LibraryContainerLocator, isDeleted=Fal
192192
raise ContentLibraryContainerNotFound
193193

194194

195-
def get_container(container_key: LibraryContainerLocator, include_collections=False) -> ContainerMetadata:
195+
def get_container(
196+
container_key: LibraryContainerLocator,
197+
*,
198+
include_collections=False,
199+
container: Container | None = None,
200+
) -> ContainerMetadata:
196201
"""
197202
Get a container (a Section, Subsection, or Unit).
198203
"""
199-
container = get_container_from_key(container_key)
204+
if not container:
205+
container = get_container_from_key(container_key)
206+
assert container.key == container_key.container_id
200207
if include_collections:
201208
associated_collections = authoring_api.get_entity_collections(
202209
container.publishable_entity.learning_package_id,
@@ -372,12 +379,16 @@ def restore_container(container_key: LibraryContainerLocator) -> None:
372379

373380
def get_container_children(
374381
container_key: LibraryContainerLocator,
382+
*,
375383
published=False,
384+
container: Container | None = None,
376385
) -> list[LibraryXBlockMetadata | ContainerMetadata]:
377386
"""
378387
Get the entities contained in the given container (e.g. the components/xblocks in a unit)
379388
"""
380-
container = get_container_from_key(container_key)
389+
if not container:
390+
container = get_container_from_key(container_key)
391+
assert container.key == container_key.container_id
381392
if container_key.container_type == ContainerType.Unit.value:
382393
child_components = authoring_api.get_components_in_unit(container.unit, published=published)
383394
return [LibraryXBlockMetadata.from_component(

openedx/core/djangoapps/content_libraries/rest_api/containers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ def get(self, request, container_key: LibraryContainerLocator):
184184
request.user,
185185
permissions.CAN_VIEW_THIS_CONTENT_LIBRARY,
186186
)
187-
child_entities = api.get_container_children(container_key, published)
187+
child_entities = api.get_container_children(container_key, published=published)
188+
# TODO -- this looks backwards?
188189
if container_key.container_type == api.ContainerType.Unit.value:
189190
data = serializers.LibraryXBlockMetadataSerializer(child_entities, many=True).data
190191
else:

0 commit comments

Comments
 (0)