From 1eec8b80e43a0fd4c746aa53c5d04ba30be39088 Mon Sep 17 00:00:00 2001 From: KyryloKireiev Date: Tue, 8 Oct 2024 17:47:43 +0300 Subject: [PATCH] fix: [AXM-549] Use more efficient query --- lms/djangoapps/mobile_api/users/views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/mobile_api/users/views.py b/lms/djangoapps/mobile_api/users/views.py index 091eb05403..d634b3072d 100644 --- a/lms/djangoapps/mobile_api/users/views.py +++ b/lms/djangoapps/mobile_api/users/views.py @@ -641,11 +641,12 @@ class UserEnrollmentsStatus(views.APIView): """ Gets course ids where user has completions. """ - user_completions_last_month = BlockCompletion.objects.filter( + context_keys = BlockCompletion.objects.filter( user__username=username, created__gte=active_status_date - ) - return [str(completion.block_key.course_key) for completion in user_completions_last_month] + ).values_list('context_key', flat=True).distinct() + + return [str(context_key) for context_key in context_keys] class UserCourseEnrollmentsV4Pagination(DefaultPagination):