Skip to content

Commit

Permalink
Drive by performance improvements
Browse files Browse the repository at this point in the history
Couple of tiny things I noticed when looking at the alt text bug.

This removes a duplicate query and reduces the amount of data we're loading into memory
  • Loading branch information
symroe committed Nov 5, 2024
1 parent 9f36898 commit 3e309a4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions democracy_club/apps/hermes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ class PostListView(ListView):
template_name = "hermes/post_list.html"

def get_queryset(self):
qs = self.model.objects.published().prefetch_related("author")
qs = (
self.model.objects.published()
.prefetch_related("author")
.defer("body", "hero_alt_text")
)
tag = self.request.GET.get("tag", None)
if tag:
qs = qs.for_tag(tag)
return qs

def get_context_data(self, **kwargs):
context = super(PostListView, self).get_context_data(**kwargs)
posts = Post.objects.all().published()
tags = []
for post in posts:
for post in context["object_list"]:
for tag in post.tags:
if tag not in tags:
tags.append(tag)
Expand Down

0 comments on commit 3e309a4

Please sign in to comment.