From 8b467666f84d7a38106de25b43abd05f1e476e84 Mon Sep 17 00:00:00 2001 From: Christian Zosel Date: Mon, 9 Dec 2024 10:26:40 +0100 Subject: [PATCH] chore: add prefetching --- caluma/caluma_form/signals.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/caluma/caluma_form/signals.py b/caluma/caluma_form/signals.py index 1671ddedc..6c9b24973 100644 --- a/caluma/caluma_form/signals.py +++ b/caluma/caluma_form/signals.py @@ -138,11 +138,12 @@ def update_calc_from_answer(sender, instance, **kwargs): return print(f"saved answer to {instance.question.pk}, recalculate dependents:") + document = models.Document.objects.filter(pk=instance.document_id).prefetch_related("family__answers", "family__form__questions").first() for question in models.Question.objects.filter( pk__in=instance.question.calc_dependents ): print(f"- {question.pk}") - update_or_create_calc_answer(question, instance.document) + update_or_create_calc_answer(question, document) @receiver(post_save, sender=models.Document)