feat: Use prefetch related to reduce the number of queries to the database on public index view

This commit is contained in:
Cristian 2020-11-12 11:37:56 -05:00
parent 8cfad64271
commit c565fad75c
2 changed files with 27 additions and 57 deletions

View file

@ -98,6 +98,7 @@ class PublicArchiveView(ListView):
query = self.request.GET.get('q')
if query:
qs = Snapshot.objects.filter(title__icontains=query)
qs = qs.prefetch_related("archiveresult_set").all()
for snapshot in qs:
snapshot.icons = get_icons(snapshot)
return qs