From 55af6e59af5c110393006b351691548c87e33785 Mon Sep 17 00:00:00 2001 From: Gus Brodman Date: Tue, 28 Jul 2026 11:44:00 -0400 Subject: [PATCH] Use native query for registrar-users console user query This means we don't have to load all users and filter them out later. In practice this doesn't matter because the user table is relatively small (a few hundred) but 1. who knows what can happen in the future? 2. this makes the code analysis tools happier --- .../ui/server/console/ConsoleUsersAction.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleUsersAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleUsersAction.java index 9b47b0261dd..f3a42bc8d5d 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleUsersAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleUsersAction.java @@ -15,7 +15,6 @@ package google.registry.ui.server.console; import static com.google.common.base.Strings.isNullOrEmpty; -import static com.google.common.collect.ImmutableList.toImmutableList; import static google.registry.model.console.RegistrarRole.ACCOUNT_MANAGER; import static google.registry.model.console.RegistrarRole.TECH_CONTACT; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; @@ -357,12 +356,17 @@ private User updateUserRegistrarRoles(User user, String registrarId, RegistrarRo return updatedUser; } + @SuppressWarnings("unchecked") private ImmutableList getAllRegistrarUsers(String registrarId) { return tm().transact( () -> - tm().loadAllOf(User.class).stream() - .filter(u -> u.getUserRoles().getRegistrarRoles().containsKey(registrarId)) - .collect(toImmutableList())); + ImmutableList.copyOf( + tm().getEntityManager() + .createNativeQuery( + "SELECT * FROM \"User\" WHERE exist(registrar_roles, :registrarId)", + User.class) + .setParameter("registrarId", registrarId) + .getResultList())); } /** Maps a request role string to a RegistrarRole, using ACCOUNT_MANAGER as the default. */