From 2d65dc28c4ceb2872dc838b3c3a3061486043951 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 15 Mar 2016 11:39:35 +0000 Subject: [PATCH] views: Prefetch 'Patch.check_set' The checks for each Patch are queried each time patches are listed. This causes a deluge of queries (around one per patch). Mitigate this by instead prefetching this related attribute. This reduces the number of queries for a list of 100 patches from an average of 119 to 20. Signed-off-by: Stephen Finucane Reviewed-by: Andy Doan --- patchwork/views/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py index b12a1275..46ff7d61 100644 --- a/patchwork/views/__init__.py +++ b/patchwork/views/__init__.py @@ -263,6 +263,9 @@ def generic_list(request, project, view, # rendering the list template patches = patches.select_related('state', 'submitter', 'delegate') + # we also need checks + patches = patches.prefetch_related('check_set') + paginator = Paginator(request, patches) context.update({ -- 2.47.3