flows: optimise queries for flow and stage API endpoints

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-10-15 11:54:29 +02:00
parent 26adf3f774
commit 53aef73f58
2 changed files with 2 additions and 2 deletions

View file

@ -80,7 +80,7 @@ class FlowSerializer(ModelSerializer):
class FlowViewSet(UsedByMixin, ModelViewSet):
"""Flow Viewset"""
queryset = Flow.objects.all()
queryset = Flow.objects.all().prefetch_related("stages")
serializer_class = FlowSerializer
lookup_field = "slug"
ordering = ["slug", "name"]

View file

@ -61,7 +61,7 @@ class StageViewSet(
filterset_fields = ["name"]
def get_queryset(self): # pragma: no cover
return Stage.objects.select_subclasses()
return Stage.objects.select_subclasses().prefetch_related("flow_set")
@extend_schema(responses={200: TypeCreateSerializer(many=True)})
@action(detail=False, pagination_class=None, filter_backends=[])