]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
views: Prefetch 'Patch.check_set'
authorStephen Finucane <stephen.finucane@intel.com>
Tue, 15 Mar 2016 11:39:35 +0000 (11:39 +0000)
committerStephen Finucane <stephen.finucane@intel.com>
Mon, 21 Mar 2016 18:20:29 +0000 (18:20 +0000)
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 <stephen.finucane@intel.com>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
patchwork/views/__init__.py

index 00ff96e84f9a86fecca2c0059f2078ccbf4869fe..ae0d561d690f0a02f76575ed5ad2afe249ad961f 100644 (file)
@@ -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({