From: Stephen Finucane Date: Mon, 15 May 2017 23:13:29 +0000 (+0100) Subject: REST: Stop including 'tags' in '/patches' X-Git-Tag: v2.0.0-rc2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42def013fe468ef2b112dd345987515edcc62d07;p=thirdparty%2Fpatchwork.git REST: Stop including 'tags' in '/patches' 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 --- diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py index 294c5f62..7247b110 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 2b064a25..3c11bcae 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."""