[Patchew-devel] [PATCH] add "generation" field to message

Paolo Bonzini posted 1 patch 1 week, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew-ci tags/patchew/20211013145149.361359-1-pbonzini@redhat.com
api/migrations/0061_message_gen.py          |  18 +++++++++++++
api/models.py                               |   1 +
api/rest.py                                 |   1 +
mods/tags.py                                |   6 +++++
tests/data/0036-simple-patch-review.mbox.gz | Bin 0 -> 276 bytes
tests/test_tags.py                          |  27 ++++++++++++++++++++
6 files changed, 53 insertions(+)
create mode 100644 api/migrations/0061_message_gen.py
create mode 100644 tests/data/0036-simple-patch-review.mbox.gz

[Patchew-devel] [PATCH] add "generation" field to message

Posted by Paolo Bonzini 1 week, 1 day ago
Add a field that can be used to track changes to the mbox file.  It
changes every time a message receives a tag, or for a cover letter
every time a message underneath receives a tag.

This can be used to avoid downloading the same mbox again and again;
for example the "patches" tool (https://github.com/stefanha/patches)
had a similar feature, which it implemented using a hash of the mbox.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 api/migrations/0061_message_gen.py          |  18 +++++++++++++
 api/models.py                               |   1 +
 api/rest.py                                 |   1 +
 mods/tags.py                                |   6 +++++
 tests/data/0036-simple-patch-review.mbox.gz | Bin 0 -> 276 bytes
 tests/test_tags.py                          |  27 ++++++++++++++++++++
 6 files changed, 53 insertions(+)
 create mode 100644 api/migrations/0061_message_gen.py
 create mode 100644 tests/data/0036-simple-patch-review.mbox.gz

diff --git a/api/migrations/0061_message_gen.py b/api/migrations/0061_message_gen.py
new file mode 100644
index 0000000..d4a8646
--- /dev/null
+++ b/api/migrations/0061_message_gen.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.1.3 on 2021-10-13 14:23
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0060_auto_20210106_1120'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='message',
+            name='gen',
+            field=models.PositiveSmallIntegerField(default=0),
+        ),
+    ]
diff --git a/api/models.py b/api/models.py
index 5879466..18a09dd 100644
--- a/api/models.py
+++ b/api/models.py
@@ -593,6 +593,7 @@ class Message(models.Model):
     subject = HeaderFieldModel()
     stripped_subject = HeaderFieldModel(db_index=True)
     version = models.PositiveSmallIntegerField(default=0)
+    gen = models.PositiveSmallIntegerField(default=0)
     sender = jsonfield.JSONCharField(max_length=4096, db_index=True)
     recipients = jsonfield.JSONField()
     tags = jsonfield.JSONField(default=[])
diff --git a/api/rest.py b/api/rest.py
index b723997..fd767e2 100644
--- a/api/rest.py
+++ b/api/rest.py
@@ -374,6 +374,7 @@ class BaseMessageSerializer(serializers.ModelSerializer):
             "date",
             "sender",
             "recipients",
+            "gen",
         )
         fields = read_only_fields + ("tags",)
 
diff --git a/mods/tags.py b/mods/tags.py
index e2308b3..9c7ba0d 100644
--- a/mods/tags.py
+++ b/mods/tags.py
@@ -71,6 +71,9 @@ series cover letter, patch mail body and their replies.
         new = self.look_for_tags(s, s)
         if set(old) != set(new):
             s.tags = list(set(new))
+            # The gen field for series is updated later
+            if s.is_patch:
+                s.gen += 1
             s.save()
             return True
 
@@ -127,6 +130,9 @@ series cover letter, patch mail body and their replies.
             if need_event:
                 emit_event("SeriesReviewed", series=series)
         if updated:
+            if not series.is_patch:
+                series.gen += 1
+                series.save()
             emit_event("TagsUpdate", series=series)
 
         if not series.topic.latest or newer_than(series, series.topic.latest):
diff --git a/tests/data/0036-simple-patch-review.mbox.gz b/tests/data/0036-simple-patch-review.mbox.gz
new file mode 100644
index 0000000000000000000000000000000000000000..c401938bd3772067dd50d5114649980fdf4378f9
GIT binary patch
literal 276
zcmV+v0qg!BiwFo8@@8QG128Z%HZ5~$ZE$R5EpTCUV`wdMWp-(0cP?#WZ+HNWkV{X)
zFc5_A{uO%%M@|TF8dWGfga8RqN^VsTPP3#&e$|Ov(qE6ON=V$0_OOSU*>C63TV26I
zSY_ePnxixl=B_<&wa0EN#$;pl4QXrzJJf-8xJOkRYkCtB>wEGbMy#L-cnMhvFTp^@
z(gN75%6S~PU?pSZ*-(#8P4pBrKPgy|l`PG9&XbJIcuG_HDfIEr)mIz_(Ib^zG^N>9
zeqHdg#&4mW!n5Qfv|qRxD_Fh%;;mt|xNYvA*079dyI_5YZ@w8dLG(DO5Dr^3Fa+nU
aAF(53iF=6$>}WgvuaF;%soW7e0RRBa6?|#{

literal 0
HcmV?d00001

diff --git a/tests/test_tags.py b/tests/test_tags.py
index 101a39d..a9d4a5c 100755
--- a/tests/test_tags.py
+++ b/tests/test_tags.py
@@ -33,6 +33,33 @@ class ImportTest(PatchewTestCase):
         )
         self.assertEquals(resp.status_code, 404)
 
+    def test_message_generation(self):
+        resp = self.apply_and_retrieve(
+            "0001-simple-patch.mbox.gz",
+            self.p.id,
+            "20160628014747.20971-1-famz@redhat.com")
+        message = self.api_client.get(resp.data["message"])
+        gen = message.data["gen"]
+
+        resp = self.apply_and_retrieve(
+            "0036-simple-patch-review.mbox.gz",
+            self.p.id,
+            "20160628014747.20971-1-famz@redhat.com")
+        message = self.api_client.get(resp.data["message"])
+        self.assertGreater(message.data["gen"], gen)
+
+    def test_series_generation(self):
+        resp = self.apply_and_retrieve(
+            "0001-simple-patch.mbox.gz",
+            self.p.id,
+            "20160628014747.20971-1-famz@redhat.com")
+        gen = resp.data["gen"]
+        resp = self.apply_and_retrieve(
+            "0036-simple-patch-review.mbox.gz",
+            self.p.id,
+            "20160628014747.20971-1-famz@redhat.com")
+        self.assertGreater(resp.data["gen"], gen)
+
     def test_rest_single(self):
         resp = self.apply_and_retrieve(
             "0003-single-patch-reviewed.mbox.gz",
-- 
2.31.1

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