diff mbox

views: Prefetch 'Patch.check_set'

Message ID 1458069390-18442-1-git-send-email-stephen.finucane@intel.com
State Accepted
Headers show

Commit Message

Stephen Finucane March 15, 2016, 7:16 p.m. UTC
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@intel.com>
---
 patchwork/views/__init__.py | 3 +++
 1 file changed, 3 insertions(+)

Comments

Andy Doan March 15, 2016, 9:01 p.m. UTC | #1
On 03/15/2016 02:16 PM, Stephen Finucane wrote:
> 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@intel.com>

Reviewed-by: Andy Doan <andy.doan@linaro.org>
Stephen Finucane March 16, 2016, 9:52 a.m. UTC | #2
On 15 Mar 16:01, Andy Doan wrote:
> On 03/15/2016 02:16 PM, Stephen Finucane wrote:
> >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@intel.com>
> 
> Reviewed-by: Andy Doan <andy.doan@linaro.org>

Merged. Thanks for the review.
Stephen Finucane March 21, 2016, 6:22 p.m. UTC | #3
On 16 Mar 09:52, Finucane, Stephen wrote:
> On 15 Mar 16:01, Andy Doan wrote:
> > On 03/15/2016 02:16 PM, Stephen Finucane wrote:
> > >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@intel.com>
> > 
> > Reviewed-by: Andy Doan <andy.doan@linaro.org>
> 
> Merged. Thanks for the review.

Also backported to 'stable/1.1', as this is pretty much a performance
bug.
diff mbox

Patch

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({