In order to find unapplied MessageResults for a given set of projects,
the database would have to walk all the messages for the project and
jump from Message to MessageResult to Result. For efficiency,
look up the project, name ("git") and status ("pending") in a
single index.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
api/migrations/0070_auto_20220919_1016.py | 17 +++++++++++++++++
api/models.py | 2 +-
mods/git.py | 6 ++----
3 files changed, 20 insertions(+), 5 deletions(-)
create mode 100644 api/migrations/0070_auto_20220919_1016.py
diff --git a/api/migrations/0070_auto_20220919_1016.py b/api/migrations/0070_auto_20220919_1016.py
new file mode 100644
index 0000000..5ea23c1
--- /dev/null
+++ b/api/migrations/0070_auto_20220919_1016.py
@@ -0,0 +1,17 @@
+# Generated by Django 3.1.14 on 2022-09-19 10:16
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('api', '0069_auto_20220919_1008'),
+ ]
+
+ operations = [
+ migrations.AlterIndexTogether(
+ name='result',
+ index_together={('status', 'name', 'project')},
+ ),
+ ]
diff --git a/api/models.py b/api/models.py
index b942e20..b1b42c1 100644
--- a/api/models.py
+++ b/api/models.py
@@ -69,7 +69,7 @@ class Result(models.Model):
)
class Meta:
- index_together = [("status", "name")]
+ index_together = [("status", "name", "project")]
def is_success(self):
return self.status == self.SUCCESS
diff --git a/mods/git.py b/mods/git.py
index 5b3dddc..8220d5d 100644
--- a/mods/git.py
+++ b/mods/git.py
@@ -283,8 +283,6 @@ class GitModule(PatchewModule):
)
def pending_series(self, target_repo):
- q = Message.objects.filter(results__name="git", results__status="pending")
-
# Postgres could use JSON fields instead. Fortunately projects are
# few so this is cheap
def match_target_repo(config, target_repo):
@@ -302,8 +300,8 @@ class GitModule(PatchewModule):
projects = [
pid for pid, config in projects if match_target_repo(config, target_repo)
]
- q = q.filter(project__pk__in=projects)
- return q
+ return Message.objects.filter(results__name="git", results__status="pending",
+ results__project__pk__in=projects)
class UnappliedSeriesSerializer(SeriesSerializer):
--
2.37.2
_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/patchew-devel