Commit b7fba98e by jarv

Merge pull request #1790 from MITx/fix/cdodge/certificates-db-perf-optimization

optimize db round trips, by getting the course descriptor outside of the...
parents 140ad8bf 8fef8307
......@@ -73,6 +73,9 @@ class Command(BaseCommand):
ended_courses.append(course_id)
for course_id in ended_courses:
# prefetch all chapters/sequentials by saying depth=2
course = modulestore().get_instance(course_id, CourseDescriptor.id_to_location(course_id), depth=2)
print "Fetching enrolled students for {0}".format(course_id)
enrolled_students = User.objects.filter(
courseenrollment__course_id=course_id).prefetch_related(
......@@ -99,6 +102,6 @@ class Command(BaseCommand):
student, course_id)['status'] in valid_statuses:
if not options['noop']:
# Add the certificate request to the queue
ret = xq.add_cert(student, course_id)
ret = xq.add_cert(student, course_id, course=course)
if ret == 'generating':
print '{0} - {1}'.format(student, ret)
......@@ -115,7 +115,7 @@ class XQueueCertInterface(object):
raise NotImplementedError
def add_cert(self, student, course_id):
def add_cert(self, student, course_id, course=None):
"""
Arguments:
......@@ -151,9 +151,12 @@ class XQueueCertInterface(object):
if cert_status in VALID_STATUSES:
# grade the student
course = courses.get_course_by_id(course_id)
profile = UserProfile.objects.get(user=student)
# re-use the course passed in optionally so we don't have to re-fetch everything
# for every student
if course is None:
course = courses.get_course_by_id(course_id)
profile = UserProfile.objects.get(user=student)
cert, created = GeneratedCertificate.objects.get_or_create(
user=student, course_id=course_id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment