From 89a60823958f10f1d041c0f290a32b97f2e3600f Mon Sep 17 00:00:00 2001 From: Mickael Jeanroy <1067361+mjeanroy@users.noreply.github.com> Date: Sun, 28 May 2023 14:06:37 +0200 Subject: [PATCH] perf: improve performance of get_user_id (#449) --- src/keycloak/keycloak_admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/keycloak/keycloak_admin.py b/src/keycloak/keycloak_admin.py index 8ee275a..d2826b6 100644 --- a/src/keycloak/keycloak_admin.py +++ b/src/keycloak/keycloak_admin.py @@ -850,8 +850,8 @@ class KeycloakAdmin: :rtype: str """ lower_user_name = username.lower() - users = self.get_users(query={"search": lower_user_name}) - return next((user["id"] for user in users if user["username"] == lower_user_name), None) + users = self.get_users(query={"username": lower_user_name, "max": 1, "exact": True}) + return users[0]["id"] if len(users) == 1 else None def get_user(self, user_id): """Get representation of the user.