[PATCH 2/6] REST: Stop including 'tags' in '/patches'

Stephen Finucane stephen at that.guru
Tue May 16 09:14:31 AEST 2017


While this is a very helpful field to include, doing so significantly
increases the number of DB queries necessary for listing patches (from
~14 to ~46). Stop including this information until the model itself is
reworked to prevent this issue.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/api/patch.py           | 12 +++++-------
 patchwork/tests/test_rest_api.py |  3 +--
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
index 294c5f6..7247b11 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -84,11 +84,9 @@ class PatchListSerializer(HyperlinkedModelSerializer):
         return request.build_absolute_uri(instance.get_mbox_url())
 
     def get_tags(self, instance):
-        if instance.project.tags:
-            return {x.name: getattr(instance, x.attr_name)
-                    for x in instance.project.tags}
-        else:
-            return None
+        # TODO(stephenfin): Make tags performant, possibly by reworking the
+        # model
+        return {}
 
     def get_check(self, instance):
         return instance.combined_check_state
@@ -149,7 +147,7 @@ class PatchList(ListAPIView):
     def get_queryset(self):
         # TODO(stephenfin): Does the defer here cause issues with Django 1.6
         # (like /cover)?
-        return Patch.objects.all().with_tag_counts()\
+        return Patch.objects.all()\
             .prefetch_related('series', 'check_set')\
             .select_related('project', 'state', 'submitter', 'delegate')\
             .defer('content', 'diff', 'headers')
@@ -162,6 +160,6 @@ class PatchDetail(RetrieveUpdateAPIView):
     serializer_class = PatchDetailSerializer
 
     def get_queryset(self):
-        return Patch.objects.all().with_tag_counts()\
+        return Patch.objects.all()\
             .prefetch_related('series', 'check_set')\
             .select_related('project', 'state', 'submitter', 'delegate')
diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py
index c63f672..236b3dc 100644
--- a/patchwork/tests/test_rest_api.py
+++ b/patchwork/tests/test_rest_api.py
@@ -357,8 +357,7 @@ class TestPatchAPI(APITestCase):
         self.assertEqual(patch.headers, resp.data['headers'] or '')
         self.assertEqual(patch.content, resp.data['content'])
         self.assertEqual(patch.diff, resp.data['diff'])
-        self.assertEqual(3, len(resp.data['tags']))
-        self.assertEqual(1, resp.data['tags']['Reviewed-by'])
+        self.assertEqual(0, len(resp.data['tags']))
 
     def test_create(self):
         """Ensure creations are rejected."""
-- 
2.9.3



More information about the Patchwork mailing list