From 2200b0d4369389f327c937696f5743fca9d979cc Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 15 Oct 2021 09:21:01 +0200 Subject: [PATCH] Reduce gallery load time by prefetching owners --- photologue_custom/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/photologue_custom/views.py b/photologue_custom/views.py index 509f6b8..c12d0a1 100644 --- a/photologue_custom/views.py +++ b/photologue_custom/views.py @@ -51,7 +51,9 @@ class CustomGalleryDetailView(DetailView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context['photos'] = self.object.public() + + # Query with extended and owner to reduce database lag + context['photos'] = self.object.public().select_related('extended__owner') # List owners context['owners'] = []