]> git.ipfire.org Git - thirdparty/patchwork.git/commit
Optimise querying of checks in patch list view
authorDaniel Axtens <dja@axtens.net>
Thu, 15 Sep 2016 08:10:29 +0000 (18:10 +1000)
committerStephen Finucane <stephenfinucane@hotmail.com>
Mon, 19 Sep 2016 23:32:40 +0000 (00:32 +0100)
commit69115bf54ef4faa6d01d04ed4dc0ac52a68e8962
treea5219dbe139253fe04670ba37c2b73c3083b7cb5
parent08f00f1ba5d4d02eb9b0af2cfc35f563428a117f
Optimise querying of checks in patch list view

tl;dr: with about 300 mails from the patchwork list, according to
django-debug-toolbar, to render '/project/patchwork/list/'

Without this patch:
 - ~1.35 seconds of CPU time
 - 110 SQL queries, taking ~70ms

With this patch:
 - < 0.3 seconds of CPU time
 - 10 SQL queries, taking <20ms

How? Replace an .exclude() on a QuerySet with a list comprehension.
Yes, that's normally a pessimisation.  Surprisingly, it's an
optimisation here.  Why? Where we're looking at patches in anything
that uses a generic_list() in the view, we do a prefetch_related. But,
if we then do a .filter or a .exclude, that throws out the existing,
cached information, and does another query. (See the Django docs on
prefetch_related)

So, do it 'by hand' in Python instead.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephenfinucane@hotmail.com>
patchwork/models.py