Skip to content

Commit

Permalink
Merge pull request #1952 from laws-africa/n-plus-1
Browse files Browse the repository at this point in the history
reduce n+1 queries
  • Loading branch information
longhotsummer authored Aug 2, 2024
2 parents 7991e8e + b781787 commit b07c276
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion peachjam/views/courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FilteredJudgmentView(FilteredDocumentListView):
navbar_link = "judgments"
queryset = Judgment.objects.prefetch_related(
"judges", "labels", "attorneys", "outcomes"
)
).select_related("work")
exclude_facets = []
group_by_date = "month-year"

Expand Down
10 changes: 6 additions & 4 deletions peachjam/views/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@


class JudgmentListView(TemplateView):
model = Judgment
template_name = "peachjam/judgment_list.html"
navbar_link = "judgments"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

context["court_classes"] = CourtClass.objects.prefetch_related("courts")
context["recent_judgments"] = Judgment.objects.exclude(
published=False
).order_by("-date")[:30]
context["recent_judgments"] = (
Judgment.objects.select_related("work")
.prefetch_related("labels")
.exclude(published=False)
.order_by("-date")[:30]
)
context["doc_type"] = "Judgment"
context["doc_count"] = Judgment.objects.filter(published=True).count()
context["help_link"] = "judgments/courts"
Expand Down

0 comments on commit b07c276

Please sign in to comment.