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): class FlowViewSet(UsedByMixin, ModelViewSet):
"""Flow Viewset""" """Flow Viewset"""
queryset = Flow.objects.all() queryset = Flow.objects.all().prefetch_related("stages")
serializer_class = FlowSerializer serializer_class = FlowSerializer
lookup_field = "slug" lookup_field = "slug"
ordering = ["slug", "name"] ordering = ["slug", "name"]

View file

@ -61,7 +61,7 @@ class StageViewSet(
filterset_fields = ["name"] filterset_fields = ["name"]
def get_queryset(self): # pragma: no cover 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)}) @extend_schema(responses={200: TypeCreateSerializer(many=True)})
@action(detail=False, pagination_class=None, filter_backends=[]) @action(detail=False, pagination_class=None, filter_backends=[])