]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: Cache 'list_archive_url' property
authorStephen Finucane <stephen@that.guru>
Fri, 30 Sep 2022 15:10:27 +0000 (16:10 +0100)
committerStephen Finucane <stephen@that.guru>
Fri, 30 Sep 2022 16:38:54 +0000 (17:38 +0100)
We really need to get rid of this from the embedded view. It's way too
slow. For now, we just cache it and leave a note for future us.

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/api/embedded.py
patchwork/models.py

index 7105da08fed2d382406bf0536a74d377d0b7828c..4cfdf8e622e97b667812433474dec625658d65fc 100644 (file)
@@ -113,6 +113,8 @@ class CoverSerializer(SerializedRelatedField):
                 'url',
                 'web_url',
                 'msgid',
+                # TODO(stephenfin): Drop this in a future API version - it is
+                # too slow to calculate and not necessary here.
                 'list_archive_url',
                 'date',
                 'name',
@@ -149,6 +151,8 @@ class CoverCommentSerializer(SerializedRelatedField):
                 'url',
                 'web_url',
                 'msgid',
+                # TODO(stephenfin): Drop this in a future API version - it is
+                # too slow to calculate and not necessary here.
                 'list_archive_url',
                 'date',
             )
@@ -174,6 +178,8 @@ class PatchSerializer(SerializedRelatedField):
                 'url',
                 'web_url',
                 'msgid',
+                # TODO(stephenfin): Drop this in a future API version - it is
+                # too slow to calculate and not necessary here.
                 'list_archive_url',
                 'date',
                 'name',
@@ -207,6 +213,8 @@ class PatchCommentSerializer(SerializedRelatedField):
                 'url',
                 'web_url',
                 'msgid',
+                # TODO(stephenfin): Drop this in a future API version - it is
+                # too slow to calculate and not necessary here.
                 'list_archive_url',
                 'date',
             )
@@ -253,8 +261,12 @@ class ProjectSerializer(SerializedRelatedField):
                 'web_url',
                 'scm_url',
                 'webscm_url',
+                # TODO(stephenfin): Drop this in a future API version - it is
+                # too slow to calculate and not necessary here.
                 'list_archive_url',
+                # TODO(stephenfin): Ditto
                 'list_archive_url_format',
+                # TODO(stephenfin): Ditto
                 'commit_url_format',
             )
             read_only_fields = fields
index 264af532e94268e62374eef2d24825c24bd214e3..d2507d4fdef239339dc2729df51b59ad4dd75752 100644 (file)
@@ -406,7 +406,7 @@ class SubmissionMixin(FilenameMixin, EmailMixin, models.Model):
 
     name = models.CharField(max_length=255)
 
-    @property
+    @cached_property
     def list_archive_url(self):
         if not self.project.list_archive_url_format:
             return None
@@ -719,7 +719,7 @@ class CoverComment(EmailMixin, models.Model):
     )
     addressed = models.BooleanField(null=True)
 
-    @property
+    @cached_property
     def list_archive_url(self):
         if not self.cover.project.list_archive_url_format:
             return None
@@ -770,7 +770,7 @@ class PatchComment(EmailMixin, models.Model):
     )
     addressed = models.BooleanField(null=True)
 
-    @property
+    @cached_property
     def list_archive_url(self):
         if not self.patch.project.list_archive_url_format:
             return None