[PATCH] views: Prefetch 'Patch.check_set'

Stephen Finucane stephen.finucane at intel.com
Wed Mar 16 06:16:30 AEDT 2016


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 from an average of 119 to 20.

Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
 patchwork/views/__init__.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py
index 00ff96e..ae0d561 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.0.0



More information about the Patchwork mailing list