]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
REST: Resolve performance issues with '/events' web view
authorStephen Finucane <stephen@that.guru>
Thu, 10 May 2018 14:45:05 +0000 (15:45 +0100)
committerDaniel Axtens <dja@axtens.net>
Fri, 11 May 2018 16:45:25 +0000 (02:45 +1000)
The dropdown select-based filters in the web view of the REST API have
stung us a few times. In this case, populating these filters for the
'/events' endpoint results in a huge query that hammers the database and
results in seriously laggy responses.

The root cause of this performance issues was erroneously identified as
an issue with the JSON renderer so that particular patch can now be
reverted. This will be done separately.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Cc: Daniel Axtens <dja@axtens.net>
Tested-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Daniel Axtens <dja@axtens.net>
patchwork/api/filters.py

index f6fff792df8dac97a22af29792c4d082f90dc12a..7e818954639a1a3613e652d875c87f1d4bb65bb3 100644 (file)
@@ -24,6 +24,7 @@ from django_filters.rest_framework import FilterSet
 from django_filters import IsoDateTimeFilter
 from django_filters import ModelMultipleChoiceFilter
 from django.forms import ModelMultipleChoiceField as BaseMultipleChoiceField
+from django.forms.widgets import MultipleHiddenInput
 
 from patchwork.models import Bundle
 from patchwork.models import Check
@@ -200,10 +201,17 @@ class CheckFilterSet(TimestampMixin, FilterSet):
 
 class EventFilterSet(TimestampMixin, FilterSet):
 
-    project = ProjectFilter(queryset=Project.objects.all())
-    series = BaseFilter(queryset=Series.objects.all())
-    patch = BaseFilter(queryset=Patch.objects.all())
-    cover = BaseFilter(queryset=CoverLetter.objects.all())
+    # NOTE(stephenfin): We disable the select-based HTML widgets for these
+    # filters as the resulting query is _huge_
+    # TODO(stephenfin): We should really use an AJAX widget of some form here
+    project = ProjectFilter(queryset=Project.objects.all(),
+                            widget=MultipleHiddenInput)
+    series = BaseFilter(queryset=Series.objects.all(),
+                        widget=MultipleHiddenInput)
+    patch = BaseFilter(queryset=Patch.objects.all(),
+                       widget=MultipleHiddenInput)
+    cover = BaseFilter(queryset=CoverLetter.objects.all(),
+                       widget=MultipleHiddenInput)
 
     class Meta:
         model = Event