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
This commit is contained in:
Zainab Amir
2019-05-14 15:19:03 +05:00
parent 489c78dfa7
commit fd15fcc47d

View File

@@ -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']
)