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 4ea7eb4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions deviations/viewbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,15 @@ 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')
)
Expand Down

0 comments on commit 4ea7eb4

Please sign in to comment.