]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
api: do not fetch every patch in a patch detail view 404
authorDaniel Axtens <dja@axtens.net>
Tue, 14 Apr 2020 04:26:58 +0000 (14:26 +1000)
committerDaniel Axtens <dja@axtens.net>
Tue, 14 Apr 2020 13:28:15 +0000 (23:28 +1000)
mpe and jk and sfr found that the OzLabs server was melting due
to some queries downloading every patch.

Turns out if you 404 the patch detail view in the API, d-r-f attempts
to render a listbox with every single patch to fill in the 'related'
field. The bundle API also has a similar field.

Replace the multiple selection box with a text field. You can still
(AIUI) populate the relevant patch IDs manually.

This is the recommended approach per
https://www.django-rest-framework.org/topics/browsable-api/#handling-choicefield-with-large-numbers-of-items

Reported-by: Jeremy Kerr <jk@ozlabs.org>
Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Tested-by: Jeremy Kerr <jk@ozlabs.org>
Server-no-longer-on-fire-by: Jeremy Kerr <jk@ozlabs.org>
Reviewed-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Daniel Axtens <dja@axtens.net>
(cherry picked from commit 08c5856444bc2e100c4acbbea0a244cd46083c4b)

patchwork/api/bundle.py
patchwork/api/embedded.py

index b8c0f17817861fc2a8c8746986028d890efdf1cf..54a9266e7d7318e5a1beec720d971359bb5e2a73 100644 (file)
@@ -62,7 +62,8 @@ class BundleSerializer(BaseHyperlinkedModelSerializer):
     project = ProjectSerializer(read_only=True)
     mbox = SerializerMethodField()
     owner = UserSerializer(read_only=True)
-    patches = PatchSerializer(many=True, required=True)
+    patches = PatchSerializer(many=True, required=True,
+                              style={'base_template': 'input.html'})
 
     def get_web_url(self, instance):
         request = self.context.get('request')
index 85a30cae1cdf5b2248427656d000bfd9263c8cba..cb3f07e6b998da8373976de6aaeec6131d62b2df 100644 (file)
@@ -141,7 +141,8 @@ class PatchSerializer(SerializedRelatedField):
 
 class PatchRelationSerializer(BaseHyperlinkedModelSerializer):
     """Hide the PatchRelation model, just show the list"""
-    patches = PatchSerializer(many=True)
+    patches = PatchSerializer(many=True,
+                              style={'base_template': 'input.html'})
 
     def to_internal_value(self, data):
         if not isinstance(data, type([])):