From 095982a2e24b310b6ab9547dd80699b8edc5df1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Caux?= <git@jscaux.org> Date: Fri, 3 Feb 2023 21:49:13 +0100 Subject: [PATCH] Accelerate _hx_motion_voting with prefetch --- scipost_django/forums/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scipost_django/forums/views.py b/scipost_django/forums/views.py index f77755ab1..95c586ec2 100644 --- a/scipost_django/forums/views.py +++ b/scipost_django/forums/views.py @@ -395,7 +395,6 @@ def _hx_thread_from_post(request, slug, post_id): ).first() context = { "forum": forum, - # "post": post.motion if hasattr(post, "motion") else post, "post": post, } return render(request, "forums/post_card.html", context) @@ -405,7 +404,13 @@ def _hx_thread_from_post(request, slug, post_id): @permission_required_or_403("forums.can_post_to_forum", (Forum, "slug", "slug")) def _hx_motion_voting(request, slug, motion_id): forum = get_object_or_404(Forum, slug=slug) - motion = get_object_or_404(Motion, pk=motion_id) + motion = get_object_or_404(Motion.objects.prefetch_related( + "eligible_for_voting__contributor__user", + "in_agreement__contributor__user", + "in_doubt__contributor__user", + "in_disagreement__contributor__user", + "in_abstain__contributor__user", + ), pk=motion_id) initial = { "user": request.user.id, "motion": motion.id, -- GitLab