[Patchew-devel] [PATCH 5/9] remove is_series_head field

Paolo Bonzini pbonzini at redhat.com
Thu Jan 16 15:09:05 UTC 2020


This also introduces a database migration in order to undo the
removal.  The field is populated from the topic field when it is
added back.

Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
---
 api/admin.py                                  |  1 -
 api/migrations/0056_repopulate_series_head.py | 18 ++++++++++++++++++
 .../0057_remove_message_is_series_head.py     | 19 +++++++++++++++++++
 api/models.py                                 | 17 +++++++++--------
 api/rest.py                                   |  2 +-
 5 files changed, 47 insertions(+), 10 deletions(-)
 create mode 100644 api/migrations/0056_repopulate_series_head.py
 create mode 100644 api/migrations/0057_remove_message_is_series_head.py

diff --git a/api/admin.py b/api/admin.py
index d0143d2..d85f5b8 100644
--- a/api/admin.py
+++ b/api/admin.py
@@ -18,7 +18,6 @@ class ProjectAdmin(admin.ModelAdmin):
 
 
 class MessageAdmin(admin.ModelAdmin):
-    list_filter = [("is_series_head")]
     search_fields = ["message_id", "subject", "sender"]
 
 
diff --git a/api/migrations/0056_repopulate_series_head.py b/api/migrations/0056_repopulate_series_head.py
new file mode 100644
index 0000000..8ffd266
--- /dev/null
+++ b/api/migrations/0056_repopulate_series_head.py
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.conf import settings
+from django.db import migrations
+
+
+def series_head_fill(apps, schema_editor):
+    Message = apps.get_model("api", "Message")
+    Message.objects.filter(topic__isnull=False).update(is_series_head=True)
+
+
+class Migration(migrations.Migration):
+    dependencies = [("api", "0055_auto_20200116_1034")]
+
+    operations = [
+        migrations.RunPython(migrations.RunPython.noop, reverse_code=series_head_fill)
+    ]
diff --git a/api/migrations/0057_remove_message_is_series_head.py b/api/migrations/0057_remove_message_is_series_head.py
new file mode 100644
index 0000000..c0dc476
--- /dev/null
+++ b/api/migrations/0057_remove_message_is_series_head.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.20 on 2020-01-16 10:36
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0056_repopulate_series_head'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='message',
+            name='is_series_head',
+        ),
+    ]
diff --git a/api/models.py b/api/models.py
index 0435527..f5a1114 100644
--- a/api/models.py
+++ b/api/models.py
@@ -387,7 +387,7 @@ class MessageManager(models.Manager):
         if po is None:
             return None
 
-        q = super(MessageManager, self).get_queryset()
+        q = self.get_queryset()
         q = q.filter(project=po) | q.filter(project__parent_project=po)
         return q
 
@@ -397,8 +397,8 @@ class MessageManager(models.Manager):
             if q is None:
                 return None
         else:
-            q = super(MessageManager, self).get_queryset()
-        return q.filter(is_series_head=True).prefetch_related("project")
+            q = self.get_queryset()
+        return q.filter(topic__isnull=False).prefetch_related("project")
 
     def find_series(self, message_id, project_name=None):
         heads = self.series_heads(project_name)
@@ -413,7 +413,7 @@ class MessageManager(models.Manager):
         return messages.filter(message_id=message_id).first()
 
     def patches(self):
-        return super(MessageManager, self).get_queryset().filter(is_patch=True)
+        return self.get_queryset().filter(is_patch=True)
 
     def update_series(self, msg):
         """Update the series' record to which @msg is replying"""
@@ -458,7 +458,6 @@ class MessageManager(models.Manager):
         msg.version = m.get_version()
         msg.prefixes = m.get_prefixes()
         if m.is_series_head():
-            msg.is_series_head = True
             msg.topic = Topic.objects.for_stripped_subject(msg.stripped_subject)
 
         msg.is_patch = m.is_patch()
@@ -493,7 +492,6 @@ class MessageManager(models.Manager):
                 sender=m.get_from(),
                 recipients=m.get_to() + m.get_cc(),
                 prefixes=m.get_prefixes(),
-                is_series_head=is_series_head,
                 topic=(
                     Topic.objects.for_stripped_subject(stripped_subject)
                     if is_series_head
@@ -577,7 +575,6 @@ class Message(models.Model):
     recipients = jsonfield.JSONField()
     tags = jsonfield.JSONField(default=[])
     prefixes = jsonfield.JSONField(blank=True)
-    is_series_head = models.BooleanField(default=False)
     is_complete = models.BooleanField(default=False)
     is_patch = models.BooleanField()
     is_merged = models.BooleanField(default=False, blank=True)
@@ -593,7 +590,7 @@ class Message(models.Model):
     # patch index number if is_patch
     patch_num = models.PositiveSmallIntegerField(null=True, blank=True)
 
-    # number of patches we've got if is_series_head
+    # number of patches we've got if series head (non-null topic)
     num_patches = models.IntegerField(null=False, default=-1, blank=True)
 
     queues = models.ManyToManyField(User, blank=True, through=QueuedSeries)
@@ -706,6 +703,10 @@ class Message(models.Model):
             project_id=self.project_id, message_id=self.in_reply_to
         ).first()
 
+    @property
+    def is_series_head(self):
+        return self.topic is not None
+
     def get_series_head(self):
         s = self
         while s:
diff --git a/api/rest.py b/api/rest.py
index a3b760c..3a9def5 100644
--- a/api/rest.py
+++ b/api/rest.py
@@ -526,7 +526,7 @@ class PatchewSearchFilter(filters.BaseFilterBackend):
 
 class SeriesViewSet(BaseMessageViewSet):
     serializer_class = SeriesSerializer
-    queryset = Message.objects.filter(is_series_head=True).order_by("-last_reply_date")
+    queryset = Message.objects.filter(topic__isnull=False).order_by("-last_reply_date")
     filter_backends = (PatchewSearchFilter,)
     search_fields = (SEARCH_PARAM,)
 
-- 
2.21.0





More information about the Patchew-devel mailing list