From 53aef73f584745175f16bb92f9ab50db80f680d7 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 15 Oct 2022 11:54:29 +0200 Subject: [PATCH] flows: optimise queries for flow and stage API endpoints Signed-off-by: Jens Langhammer --- authentik/flows/api/flows.py | 2 +- authentik/flows/api/stages.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/authentik/flows/api/flows.py b/authentik/flows/api/flows.py index 926e86208..638524236 100644 --- a/authentik/flows/api/flows.py +++ b/authentik/flows/api/flows.py @@ -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"] diff --git a/authentik/flows/api/stages.py b/authentik/flows/api/stages.py index 674e2cf36..b097f55ef 100644 --- a/authentik/flows/api/stages.py +++ b/authentik/flows/api/stages.py @@ -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=[])