Skip to content

Commit 2d65dc2

Browse files
committed
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 <stephen.finucane@intel.com> Reviewed-by: Andy Doan <andy.doan@linaro.org>
1 parent 0700831 commit 2d65dc2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

patchwork/views/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ def generic_list(request, project, view,
263263
# rendering the list template
264264
patches = patches.select_related('state', 'submitter', 'delegate')
265265

266+
# we also need checks
267+
patches = patches.prefetch_related('check_set')
268+
266269
paginator = Paginator(request, patches)
267270

268271
context.update({

0 commit comments

Comments
 (0)