feat: cache circles and learning units
This commit is contained in:
parent
eebb512348
commit
5f436da0a0
|
|
@ -1,6 +1,7 @@
|
|||
from typing import List, Tuple
|
||||
|
||||
import graphene
|
||||
from wagtail.models import Page
|
||||
|
||||
from vbv_lernwelt.course.models import CourseCompletion, CourseCompletionStatus
|
||||
|
||||
|
|
@ -38,25 +39,23 @@ def competences(
|
|||
completions = CourseCompletion.objects.filter(
|
||||
course_session_id__in=course_session_selection_ids,
|
||||
page_type="competence.PerformanceCriteria",
|
||||
)
|
||||
).prefetch_related("course_session", "page")
|
||||
|
||||
if user_selection_ids is not None:
|
||||
completions = completions.filter(user_id__in=user_selection_ids)
|
||||
|
||||
competence_records = {}
|
||||
|
||||
# purely for performance reasons, since looking up
|
||||
# the circle for each completion is expensive :-/
|
||||
circle_cache = {}
|
||||
unique_page_ids = {completion.page.id for completion in completions}
|
||||
learning_units = {
|
||||
page_id: Page.objects.get(id=page_id).specific.learning_unit
|
||||
for page_id in unique_page_ids
|
||||
}
|
||||
circles = {lu.id: lu.get_circle() for lu in learning_units.values()}
|
||||
|
||||
for completion in completions:
|
||||
if completion.page.id not in circle_cache:
|
||||
circle_cache[
|
||||
completion.page.id
|
||||
] = completion.page.specific.learning_unit.get_circle()
|
||||
|
||||
circle = circle_cache[completion.page.id]
|
||||
learning_unit = completion.page.specific.learning_unit
|
||||
learning_unit = learning_units.get(completion.page.id)
|
||||
circle = circles.get(learning_unit.id)
|
||||
|
||||
competence_records.setdefault(circle.id, {}).setdefault(
|
||||
learning_unit,
|
||||
|
|
|
|||
|
|
@ -18,10 +18,6 @@ class DashboardCompetenceTestCase(GraphQLTestCase):
|
|||
GRAPHQL_URL = "/server/graphql/"
|
||||
|
||||
def test_competence(self):
|
||||
# TODO: Livioso 30.10.2023
|
||||
# A test that checks the competence records
|
||||
# would make sense -> missing (circle, learning unit) nesting!
|
||||
|
||||
# GIVEN
|
||||
course, course_page = create_course("Test Course")
|
||||
course_session = create_course_session(course=course, title="Test Bern 2022 a")
|
||||
|
|
|
|||
Loading…
Reference in New Issue