From a8b8c89f730ed24315601ca00e050527b5f9ab63 Mon Sep 17 00:00:00 2001 From: Silvan Date: Tue, 2 Jan 2024 14:41:46 +0100 Subject: [PATCH] perf(query): increase speed of user queries (#7126) (#7128) * perf(query): increase speed of user queries --- internal/query/user_by_id.sql | 5 +++-- internal/query/user_by_login_name.sql | 6 ++++++ internal/query/user_notify_by_id.sql | 5 +++-- internal/query/user_notify_by_login_name.sql | 6 ++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/query/user_by_id.sql b/internal/query/user_by_id.sql index 67ffbb371a..8f1113de06 100644 --- a/internal/query/user_by_id.sql +++ b/internal/query/user_by_id.sql @@ -23,8 +23,6 @@ WITH login_names AS (SELECT (p.is_default IS TRUE AND p.instance_id = $2) OR (p.instance_id = $2 AND p.resource_owner = u.resource_owner) ) - AND - u.id = $1 ORDER BY is_default LIMIT 1 ) p ON TRUE @@ -33,6 +31,9 @@ WITH login_names AS (SELECT ON u.instance_id = d.instance_id AND u.resource_owner = d.resource_owner + WHERE + u.instance_id = $2 + AND u.id = $1 ) SELECT u.id diff --git a/internal/query/user_by_login_name.sql b/internal/query/user_by_login_name.sql index b9da3daa87..cf25638fa6 100644 --- a/internal/query/user_by_login_name.sql +++ b/internal/query/user_by_login_name.sql @@ -30,6 +30,12 @@ WITH found_users AS ( u.instance_id = d.instance_id AND u.resource_owner = d.resource_owner AND CASE WHEN p.must_be_domain THEN d.name_lower = $2 ELSE TRUE END + WHERE + u.instance_id = $4 + AND u.user_name_lower IN ( + $1, + $3 + ) ), login_names AS (SELECT fu.id user_id diff --git a/internal/query/user_notify_by_id.sql b/internal/query/user_notify_by_id.sql index 16905c02e6..1087a1316b 100644 --- a/internal/query/user_notify_by_id.sql +++ b/internal/query/user_notify_by_id.sql @@ -24,8 +24,6 @@ WITH login_names AS ( (p.is_default IS TRUE AND p.instance_id = $2) OR (p.instance_id = $2 AND p.resource_owner = u.resource_owner) ) - AND - u.id = $1 ORDER BY is_default LIMIT 1 ) p ON TRUE @@ -34,6 +32,9 @@ WITH login_names AS ( ON u.instance_id = d.instance_id AND u.resource_owner = d.resource_owner + WHERE + u.instance_id = $2 + AND u.id = $1 ) SELECT u.id diff --git a/internal/query/user_notify_by_login_name.sql b/internal/query/user_notify_by_login_name.sql index 47bcc8a88a..1347e6cb3c 100644 --- a/internal/query/user_notify_by_login_name.sql +++ b/internal/query/user_notify_by_login_name.sql @@ -30,6 +30,12 @@ WITH found_users AS ( u.instance_id = d.instance_id AND u.resource_owner = d.resource_owner AND CASE WHEN p.must_be_domain THEN d.name_lower = $2 ELSE TRUE END + WHERE + u.instance_id = $4 + AND u.user_name_lower IN ( + $1, + $3 + ) ), login_names AS (SELECT fu.id user_id