From: Stephen Finucane Date: Tue, 15 Mar 2016 11:39:35 +0000 (+0000) Subject: views: Prefetch 'Patch.check_set' X-Git-Tag: v2.0.0-rc1~412 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d65dc28c4ceb2872dc838b3c3a3061486043951;p=thirdparty%2Fpatchwork.git 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 --- 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({