Skip to content

Commit

Permalink
Optimization: cached content prefetches
Browse files Browse the repository at this point in the history
Generation CachedContent has been optimized by adding prefetches to its
queryset.
  • Loading branch information
skulonen committed Feb 10, 2022
1 parent bdf2ebd commit 0ac216b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion exercise/cache/content.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, Dict, List, Optional, Type, Union

from django.db.models import Prefetch
from django.db.models.base import Model
from django.db.models.signals import post_save, post_delete
from django.utils import timezone
Expand Down Expand Up @@ -98,7 +99,15 @@ def recursion(

# Collect each module.
i = 0
for module in instance.course_modules.all():
for module in instance.course_modules.prefetch_related(
'requirements',
'requirements__threshold__passed_modules',
'requirements__threshold__passed_categories',
'requirements__threshold__passed_exercises',
'requirements__threshold__passed_exercises__parent',
'requirements__threshold__points',
Prefetch('learning_objects', LearningObject.objects.all()),
):
entry = {
'type': 'module',
'id': module.id,
Expand Down

0 comments on commit 0ac216b

Please sign in to comment.