diff --git a/edxval/__init__.py b/edxval/__init__.py index 96b7b278..18647d2c 100644 --- a/edxval/__init__.py +++ b/edxval/__init__.py @@ -2,4 +2,4 @@ init """ -__version__ = '5.0.0' +__version__ = '5.0.1' diff --git a/edxval/api.py b/edxval/api.py index 8f26114a..78ecf55b 100644 --- a/edxval/api.py +++ b/edxval/api.py @@ -568,6 +568,17 @@ def create_profile(profile_name): raise ValCannotCreateError(err.message_dict) from err +def _get_video_qset(): + """ + Get a Video queryset, optionally prefetching encoded video and course information. + """ + encoded_videos = EncodedVideo.objects.select_related("profile") + course_videos = CourseVideo.objects.select_related("video_image") + return Video.objects \ + .prefetch_related(Prefetch("encoded_videos", queryset=encoded_videos)) \ + .prefetch_related(Prefetch("courses", queryset=course_videos)) + + def _get_video(edx_video_id): """ Get a Video instance, prefetching encoded video and course information. @@ -575,11 +586,7 @@ def _get_video(edx_video_id): Raises ValVideoNotFoundError if the video cannot be retrieved. """ try: - encoded_videos = EncodedVideo.objects.select_related("profile") - return Video.objects \ - .prefetch_related(Prefetch("encoded_videos", queryset=encoded_videos)) \ - .prefetch_related("courses") \ - .get(edx_video_id=edx_video_id) + return _get_video_qset().get(edx_video_id=edx_video_id) except Video.DoesNotExist as no_video_error: error_message = f"Video not found for edx_video_id: {edx_video_id}" raise ValVideoNotFoundError(error_message) from no_video_error @@ -685,7 +692,7 @@ def _get_videos_for_filter(video_filter, sort_field=None, sort_dir=SortDirection the given field and direction, with ties broken by edx_video_id to ensure a total order. """ - videos = Video.objects.filter(**video_filter) + videos = _get_video_qset().filter(**video_filter) paginator_context = {} if sort_field: