[Patchew-devel] [PATCH] models: improve topic+project index

Paolo Bonzini posted 1 patch 1 year, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew-ci tags/patchew/20220919130030.70997-2-pbonzini@redhat.com
api/migrations/0071_auto_20220919_1251.py | 17 +++++++++++++++++
api/models.py                             |  4 ++--
2 files changed, 19 insertions(+), 2 deletions(-)
create mode 100644 api/migrations/0071_auto_20220919_1251.py
[Patchew-devel] [PATCH] models: improve topic+project index
Posted by Paolo Bonzini 1 year, 6 months ago
Since most queries are project-specific, an index that places the
topic first is more effective than one that places it second.  In
fact, a topic-first index is even already present in the database
and can be useful for queries that are not specific to a project.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 api/migrations/0071_auto_20220919_1251.py | 17 +++++++++++++++++
 api/models.py                             |  4 ++--
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 api/migrations/0071_auto_20220919_1251.py

diff --git a/api/migrations/0071_auto_20220919_1251.py b/api/migrations/0071_auto_20220919_1251.py
new file mode 100644
index 0000000..3b1e089
--- /dev/null
+++ b/api/migrations/0071_auto_20220919_1251.py
@@ -0,0 +1,17 @@
+# Generated by Django 3.1.14 on 2022-09-19 12:51
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0070_auto_20220919_1016'),
+    ]
+
+    operations = [
+        migrations.AlterIndexTogether(
+            name='message',
+            index_together={('topic', 'last_reply_date'), ('project', 'topic', 'date'), ('project', 'topic', 'last_reply_date'), ('topic', 'date')},
+        ),
+    ]
diff --git a/api/models.py b/api/models.py
index 6bb9867..721366d 100644
--- a/api/models.py
+++ b/api/models.py
@@ -966,8 +966,8 @@ class Message(models.Model):
     class Meta:
         unique_together = ("project", "message_id")
         index_together = [
-            ("topic", "project", "last_reply_date"),
-            ("topic", "project", "date"),
+            ("project", "topic", "last_reply_date"),
+            ("project", "topic", "date"),
             ("topic", "last_reply_date"),
             ("topic", "date"),
         ]
-- 
2.37.2

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/patchew-devel