]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Add index for patchwork_comment (submission_id,date)
authorStewart Smith <stewart@linux.ibm.com>
Fri, 10 Aug 2018 08:00:58 +0000 (18:00 +1000)
committerStephen Finucane <stephen@that.guru>
Thu, 6 Sep 2018 19:36:21 +0000 (20:36 +0100)
This (at least theoretically) should speed up displaying comments
on patches/cover letters. It's an index that will return rows
in-order for the query that we always do ("give me the comments
on this submission in date order"), rather than having to have
the database server do a sort for us.

I haven't been able to benchmark something locally that shows
this is an actual improvement, but I don't have as large data
set as various production instances. The query plan does look
a bit nicer though. Although the benefit of index maintenance
versus how long it takes to sort things is a good question.

Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
[stephenfin: Regenerate migrations per addition of 0027 in earlier
 patch]
Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/migrations/0028_add_comment_date_index.py [new file with mode: 0644]
patchwork/models.py

diff --git a/patchwork/migrations/0028_add_comment_date_index.py b/patchwork/migrations/0028_add_comment_date_index.py
new file mode 100644 (file)
index 0000000..69a35c2
--- /dev/null
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.15 on 2018-08-31 23:44
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('patchwork', '0027_remove_series_ordering'),
+    ]
+
+    operations = [
+        migrations.AddIndex(
+            model_name='comment',
+            index=models.Index(fields=['submission', 'date'], name='submission_date_idx'),
+        ),
+    ]
index 52e7a69cd1e4f89eb3e6f7ebfc77db36d5cdbd15..fea71c879c2213c3093a33a1b631563f4e7b5993 100644 (file)
@@ -618,6 +618,10 @@ class Comment(EmailMixin, models.Model):
     class Meta:
         ordering = ['date']
         unique_together = [('msgid', 'submission')]
+        indexes = [
+            models.Index(name='submission_date_idx',
+                         fields=['submission', 'date'])
+        ]
 
 
 @python_2_unicode_compatible