Skip to content

Commit

Permalink
Optimize inefficient database query in the deviation list view
Browse files Browse the repository at this point in the history
The course module name is no longer queried separately for
each deviation. This reduces the number of performed
queries significantly. Additionally, some large unnecessary
attributes are no longer loaded.

Fixes apluslms#1302
  • Loading branch information
ihalaij1 committed Nov 7, 2023
1 parent 8f85614 commit 84691d3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion deviations/viewbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,18 @@ def get_deviation_groups(
'submitter', 'submitter__user',
'granter', 'granter__user',
'exercise', 'exercise__course_module',
'exercise__course_module__course_instance',
)
# parent is prefetched because there may be multiple ancestors, and
# they are needed for building the deviation's URL.
.defer(
'exercise__exercise_info',
'exercise__description',
'exercise__course_module__course_instance__description',
)
.prefetch_related('exercise__parent')
.order_by('submitter', 'exercise__course_module')
)

deviation_groups = groupby(
ordered_deviations,
lambda obj: (obj.submitter, obj.exercise.course_module),
Expand Down

0 comments on commit 84691d3

Please sign in to comment.