Skip to content

Commit

Permalink
Fix n+1 on judgment detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmwangemi committed Sep 12, 2023
1 parent 13e05df commit 11902a1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
26 changes: 12 additions & 14 deletions peachjam/templates/peachjam/layouts/document_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,18 @@ <h1>{{ document.title }}</h1>
</dd>
{% endif %}
{% endwith %}
{% with document.bench.all as judges %}
{% if judges %}
<dt>
{% trans 'Judges' %}
</dt>
<dd class="text-muted">
{% for bench in judges %}
{# djlint:off #}
{{ bench.judge.name }}{% if not forloop.last %},{% endif %}
{# djlint:on #}
{% endfor %}
</dd>
{% endif %}
{% endwith %}
{% if judges %}
<dt>
{% trans 'Judges' %}
</dt>
<dd class="text-muted">
{% for judge in judges %}
{# djlint:off #}
{{ judge }}{% if not forloop.last %},{% endif %}
{# djlint:on #}
{% endfor %}
</dd>
{% endif %}
{% endblock %}
{% block document-metadata-content-date %}
{% if document.doc_type == "judgment" %}
Expand Down
11 changes: 11 additions & 0 deletions peachjam/views/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ def get_context_data(self, **kwargs):
class JudgmentDetailView(BaseDocumentDetailView):
model = Judgment
template_name = "peachjam/judgment_detail.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update(
{
"judges": self.get_object()
.bench.prefetch_related("judge")
.values_list("judge__name", flat=True)
}
)
return context

0 comments on commit 11902a1

Please sign in to comment.