From fb267ee223bae8ae7443eaf827e531da317f4f74 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 13 Sep 2021 17:54:37 +0200 Subject: [PATCH] tenants: optimise db queries in middleware Signed-off-by: Jens Langhammer --- authentik/tenants/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/authentik/tenants/utils.py b/authentik/tenants/utils.py index 06b9905e2..b13861215 100644 --- a/authentik/tenants/utils.py +++ b/authentik/tenants/utils.py @@ -20,9 +20,10 @@ def get_tenant_for_request(request: HttpRequest) -> Tenant: .filter(Q(host_domain__iendswith=F("domain")) | _q_default) .order_by("default") ) - if not db_tenants.exists(): + tenants = list(db_tenants.all()) + if len(tenants) < 1: return DEFAULT_TENANT - return db_tenants.first() + return tenants[0] def context_processor(request: HttpRequest) -> dict[str, Any]: