Commit 664cafc9 by Eric Fischer Committed by GitHub

Combine get_course_blocks() calls for grading performance (#12877)

When getting progress, we need these blocks in two locations. They
do not need to be individually fetched.
parent acef4fa2
...@@ -357,13 +357,13 @@ def answer_distributions(course_key): ...@@ -357,13 +357,13 @@ def answer_distributions(course_key):
return answer_counts return answer_counts
def grade(student, course, keep_raw_scores=False): def grade(student, course, keep_raw_scores=False, course_structure=None):
""" """
Returns the grade of the student. Returns the grade of the student.
Also sends a signal to update the minimum grade requirement status. Also sends a signal to update the minimum grade requirement status.
""" """
grade_summary = _grade(student, course, keep_raw_scores) grade_summary = _grade(student, course, keep_raw_scores, course_structure)
responses = GRADES_UPDATED.send_robust( responses = GRADES_UPDATED.send_robust(
sender=None, sender=None,
username=student.username, username=student.username,
...@@ -378,7 +378,7 @@ def grade(student, course, keep_raw_scores=False): ...@@ -378,7 +378,7 @@ def grade(student, course, keep_raw_scores=False):
return grade_summary return grade_summary
def _grade(student, course, keep_raw_scores): def _grade(student, course, keep_raw_scores, course_structure=None):
""" """
Unwrapped version of "grade" Unwrapped version of "grade"
...@@ -392,7 +392,8 @@ def _grade(student, course, keep_raw_scores): ...@@ -392,7 +392,8 @@ def _grade(student, course, keep_raw_scores):
More information on the format is in the docstring for CourseGrader. More information on the format is in the docstring for CourseGrader.
""" """
course_structure = get_course_blocks(student, course.location) if course_structure is None:
course_structure = get_course_blocks(student, course.location)
grading_context_result = grading_context(course_structure) grading_context_result = grading_context(course_structure)
scorable_locations = [block.location for block in grading_context_result['all_graded_blocks']] scorable_locations = [block.location for block in grading_context_result['all_graded_blocks']]
...@@ -559,12 +560,12 @@ def grade_for_percentage(grade_cutoffs, percentage): ...@@ -559,12 +560,12 @@ def grade_for_percentage(grade_cutoffs, percentage):
return letter_grade return letter_grade
def progress_summary(student, course): def progress_summary(student, course, course_structure=None):
""" """
Returns progress summary for all chapters in the course. Returns progress summary for all chapters in the course.
""" """
progress = _progress_summary(student, course) progress = _progress_summary(student, course, course_structure)
if progress: if progress:
return progress.chapters return progress.chapters
else: else:
...@@ -579,7 +580,7 @@ def get_weighted_scores(student, course): ...@@ -579,7 +580,7 @@ def get_weighted_scores(student, course):
return _progress_summary(student, course) return _progress_summary(student, course)
def _progress_summary(student, course): def _progress_summary(student, course, course_structure=None):
""" """
Unwrapped version of "progress_summary". Unwrapped version of "progress_summary".
...@@ -598,7 +599,8 @@ def _progress_summary(student, course): ...@@ -598,7 +599,8 @@ def _progress_summary(student, course):
course: A Descriptor containing the course to grade course: A Descriptor containing the course to grade
""" """
course_structure = get_course_blocks(student, course.location) if course_structure is None:
course_structure = get_course_blocks(student, course.location)
if not len(course_structure): if not len(course_structure):
return None return None
scorable_locations = [block_key for block_key in course_structure if possibly_scored(block_key)] scorable_locations = [block_key for block_key in course_structure if possibly_scored(block_key)]
......
...@@ -40,6 +40,7 @@ import survey.utils ...@@ -40,6 +40,7 @@ import survey.utils
import survey.views import survey.views
from lms.djangoapps.ccx.utils import prep_course_for_grading from lms.djangoapps.ccx.utils import prep_course_for_grading
from certificates import api as certs_api from certificates import api as certs_api
from course_blocks.api import get_course_blocks
from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.djangoapps.models.course_details import CourseDetails
from commerce.utils import EcommerceService from commerce.utils import EcommerceService
from enrollment.api import add_enrollment from enrollment.api import add_enrollment
...@@ -716,8 +717,11 @@ def _progress(request, course_key, student_id): ...@@ -716,8 +717,11 @@ def _progress(request, course_key, student_id):
# additional DB lookup (this kills the Progress page in particular). # additional DB lookup (this kills the Progress page in particular).
student = User.objects.prefetch_related("groups").get(id=student.id) student = User.objects.prefetch_related("groups").get(id=student.id)
courseware_summary = grades.progress_summary(student, course) # Fetch course blocks once for performance reasons
grade_summary = grades.grade(student, course) course_structure = get_course_blocks(student, course.location)
courseware_summary = grades.progress_summary(student, course, course_structure)
grade_summary = grades.grade(student, course, course_structure=course_structure)
studio_url = get_studio_url(course, 'settings/grading') studio_url = get_studio_url(course, 'settings/grading')
if courseware_summary is None: if courseware_summary is None:
......
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