]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Improve patch listing performance (~3x)
authorStewart Smith <stewart@linux.ibm.com>
Fri, 10 Aug 2018 08:00:56 +0000 (18:00 +1000)
committerStephen Finucane <stephen@that.guru>
Fri, 31 Aug 2018 13:42:33 +0000 (14:42 +0100)
There's two main bits that are really expensive when composing the list
of patches for a project: the query getting the list, and the query
finding the series for each patch.

If we look at the query getting the list, it gets a lot of unnecessary
fields such as 'headers' and 'content', even though we tell Django not
to. It turns out that Django seems to ignore the Submission relationship
and I have no idea how to force it to ignore that thing (defer doesn't
work) but if we go only, then it works okay.

From my import of ~8000 messages for a few projects, my laptop query
time (MySQL, as setup by whatever the docker-compose things do) goes
from:

  http://localhost:8000/project/linux-kernel/list/
  FROM:
    342ms SQL queries cold cache, 268ms warm cache
  TO:
    118ms SQL queries cold cache, 88ms warm cache

Which is... non trivial to say the least.

The big jump is the patches.only change, and the removal of ordering
on the patchseries takes a further 10ms off. For some strange reason, it
seems rather hard to tell Django that you don't care what order the
results come back in for that query (if we do, then the db server has to
do a sort rather than just return each row)

Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
[stephenfin: Add missing migration that had been squashed into a later
 migration]
Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/migrations/0027_remove_series_ordering.py [new file with mode: 0644]
patchwork/models.py
patchwork/views/__init__.py

diff --git a/patchwork/migrations/0027_remove_series_ordering.py b/patchwork/migrations/0027_remove_series_ordering.py
new file mode 100644 (file)
index 0000000..6eec3a2
--- /dev/null
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.15 on 2018-08-31 23:42
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('patchwork', '0026_add_user_bundles_backref'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='series',
+            options={'verbose_name_plural': 'Series'},
+        ),
+    ]
index 0409d4bfe32ca4a045ee1cfdc958510ee47a46e1..52e7a69cd1e4f89eb3e6f7ebfc77db36d5cdbd15 100644 (file)
@@ -740,7 +740,6 @@ class Series(FilenameMixin, models.Model):
         return self.name if self.name else 'Untitled series #%d' % self.id
 
     class Meta:
-        ordering = ('date',)
         verbose_name_plural = 'Series'
 
 
index a30b3a61cfb7db844207a60b91f80a713dabbeb8..f66963f586d256bbd4f8f1eaced72fed7119f34a 100644 (file)
@@ -286,6 +286,9 @@ def generic_list(request, project, view, view_args=None, filter_settings=None,
     # rendering the list template
     patches = patches.select_related('state', 'submitter', 'delegate')
 
+    patches = patches.only('state', 'submitter', 'delegate', 'project',
+                           'name', 'date')
+
     # we also need checks and series
     patches = patches.prefetch_related('check_set', 'series')