From d6cc17f44a9fc42cc137e2f974fe1ef5b22fed22 Mon Sep 17 00:00:00 2001
From: Christoph Berg <myon@debian.org>
Date: Fri, 16 Oct 2026 15:58:36 +0200
Subject: [PATCH v14 05/12] Don't run the badge holder query twice

badge.html used {{ holders|length }} to choose between the compact and
the list layout and then iterated {{ holders.all }}. QuerySet.all()
returns a new clone, so the second use re-ran the holder query together
with its two prefetches (user and user__contributor): 6 queries instead
of 3 per badge page.

Iterate the holders queryset directly instead. The length filter has
already evaluated and cached it, so the loop reuses that cache.
---
 templates/contributors/badge.html | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/templates/contributors/badge.html b/templates/contributors/badge.html
index 7ea0f1fd..87d4b615 100644
--- a/templates/contributors/badge.html
+++ b/templates/contributors/badge.html
@@ -18,12 +18,12 @@
 {%if holders%}
 <h2>Badge Holders</h2>
   {%if holders|length > 50%}
-    {%for u in holders.all %}
+    {%for u in holders %}
       <nobr{%if u.date_retired%} class="badgeholder-retired"{%endif%}><a href="/community/people/{{u.user}}/">{{u.user.contributor.firstname}} {{u.user.contributor.lastname}}</a> {%if not forloop.last%}&middot;{%endif%}</nobr>
     {%endfor%}
   {%else%}
     <ul>
-      {%for u in holders.all%}
+      {%for u in holders%}
         <li{%if u.date_retired%} class="badgeholder-retired"{%endif%}><a href="/community/people/{{u.user}}/">{{u.user.contributor.firstname}} {{u.user.contributor.lastname}}</a>{%if u.date_retired%} (retired from this activity){%endif%}</li>
       {%endfor%}
     </ul>
-- 
2.53.0

