From fd15fcc47de43b03e46fd575c7a7e1d8f78c09df Mon Sep 17 00:00:00 2001 From: Zainab Amir Date: Tue, 14 May 2019 15:19:03 +0500 Subject: [PATCH] Optimize award_program_certificates task More than 70% of the execution time is spent in CPU. The change of query is to avoid the massive course_id__in the GeneratedCertificate was doing on CourseOverview PROD-67 --- lms/djangoapps/certificates/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/certificates/models.py b/lms/djangoapps/certificates/models.py index 40b5c196a6..daf6340069 100644 --- a/lms/djangoapps/certificates/models.py +++ b/lms/djangoapps/certificates/models.py @@ -226,8 +226,9 @@ class EligibleAvailableCertificateManager(EligibleCertificateManager): Return a queryset for `GeneratedCertificate` models, filtering out ineligible certificates and any linked to nonexistent courses. """ - return super(EligibleAvailableCertificateManager, self).get_queryset().filter( - course_id__in=list(CourseOverview.objects.values_list('id', flat=True)) + return super(EligibleAvailableCertificateManager, self).get_queryset().extra( + tables=['course_overviews_courseoverview'], + where=['course_id = course_overviews_courseoverview.id'] )