optimize db round trips, by getting the course descriptor outside of the user loop
This commit is contained in:
@@ -73,6 +73,9 @@ class Command(BaseCommand):
|
|||||||
ended_courses.append(course_id)
|
ended_courses.append(course_id)
|
||||||
|
|
||||||
for course_id in ended_courses:
|
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)
|
print "Fetching enrolled students for {0}".format(course_id)
|
||||||
enrolled_students = User.objects.filter(
|
enrolled_students = User.objects.filter(
|
||||||
courseenrollment__course_id=course_id).prefetch_related(
|
courseenrollment__course_id=course_id).prefetch_related(
|
||||||
@@ -99,6 +102,6 @@ class Command(BaseCommand):
|
|||||||
student, course_id)['status'] in valid_statuses:
|
student, course_id)['status'] in valid_statuses:
|
||||||
if not options['noop']:
|
if not options['noop']:
|
||||||
# Add the certificate request to the queue
|
# 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':
|
if ret == 'generating':
|
||||||
print '{0} - {1}'.format(student, ret)
|
print '{0} - {1}'.format(student, ret)
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ class XQueueCertInterface(object):
|
|||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def add_cert(self, student, course_id):
|
def add_cert(self, student, course_id, course=None):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
@@ -151,9 +151,12 @@ class XQueueCertInterface(object):
|
|||||||
|
|
||||||
if cert_status in VALID_STATUSES:
|
if cert_status in VALID_STATUSES:
|
||||||
# grade the student
|
# 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(
|
cert, created = GeneratedCertificate.objects.get_or_create(
|
||||||
user=student, course_id=course_id)
|
user=student, course_id=course_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user