mirror of
https://github.com/zitadel/zitadel.git
synced 2026-07-25 18:28:00 +00:00
# Which Problems Are Solved Login v2 uses the `users.v2.ListUsers`-endpoint to get a user by login name. This query had an inefficient `WHERE`-clause. # How the Problems Are Solved Update the view and use a specific clause for this query. # Additional information Added in https://github.com/zitadel/zitadel/pull/10475 --------- Co-authored-by: Marco A. <kwbmm1990@gmail.com> Co-authored-by: Livio Spring <9405495+livio-a@users.noreply.github.com>
42 lines
1.3 KiB
SQL
42 lines
1.3 KiB
SQL
CREATE OR REPLACE VIEW projections.login_names3 AS (
|
|
SELECT
|
|
u.id AS user_id
|
|
, CASE
|
|
WHEN p.must_be_domain THEN CONCAT(u.user_name, '@', d.name)
|
|
ELSE u.user_name
|
|
END AS login_name
|
|
, COALESCE(d.is_primary, TRUE) AS is_primary
|
|
, u.instance_id
|
|
, u.resource_owner
|
|
, CASE
|
|
WHEN p.must_be_domain THEN CONCAT(u.user_name_lower, '@', d.name_lower)
|
|
ELSE u.user_name_lower
|
|
END AS login_name_lower
|
|
FROM
|
|
projections.login_names3_users AS u
|
|
LEFT JOIN LATERAL (
|
|
SELECT
|
|
must_be_domain
|
|
, is_default
|
|
FROM
|
|
projections.login_names3_policies AS p
|
|
WHERE
|
|
(
|
|
p.instance_id = u.instance_id
|
|
AND NOT p.is_default
|
|
AND p.resource_owner = u.resource_owner
|
|
) OR (
|
|
p.instance_id = u.instance_id
|
|
AND p.is_default
|
|
)
|
|
ORDER BY
|
|
p.is_default -- custom first
|
|
LIMIT 1
|
|
) AS p ON TRUE
|
|
LEFT JOIN
|
|
projections.login_names3_domains d
|
|
ON
|
|
p.must_be_domain
|
|
AND u.resource_owner = d.resource_owner
|
|
AND u.instance_id = d.instance_id
|
|
); |