From 88a96be8968bce131463a5108aabde228cb4e339 Mon Sep 17 00:00:00 2001 From: Sergey Shcherbina Date: Thu, 31 Mar 2022 16:28:05 +0500 Subject: [PATCH] GUACAMOLE-1488: Slow selection of users on scale on Postgres --- .../guacamole/auth/jdbc/user/UserMapper.xml | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml index 94d607e337..bcd5159e17 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/resources/org/apache/guacamole/auth/jdbc/user/UserMapper.xml @@ -126,10 +126,13 @@ email_address, organization, organizational_role, - MAX(start_date) AS last_active + (SELECT start_date + FROM guacamole_user_history + WHERE user_id = guacamole_user.user_id + ORDER BY start_date desc + LIMIT 1) AS last_active FROM guacamole_user JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id - LEFT JOIN guacamole_user_history ON guacamole_user_history.user_id = guacamole_user.user_id WHERE guacamole_entity.name IN @@ -176,10 +179,13 @@ email_address, organization, organizational_role, - MAX(start_date) AS last_active + (SELECT start_date + FROM guacamole_user_history + WHERE user_id = guacamole_user.user_id + ORDER BY start_date desc + LIMIT 1) AS last_active FROM guacamole_user JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id - LEFT JOIN guacamole_user_history ON guacamole_user_history.user_id = guacamole_user.user_id WHERE guacamole_entity.name IN @@ -238,10 +244,13 @@ email_address, organization, organizational_role, - MAX(start_date) AS last_active + (SELECT start_date + FROM guacamole_user_history + WHERE user_id = guacamole_user.user_id + ORDER BY start_date desc + LIMIT 1) AS last_active FROM guacamole_user JOIN guacamole_entity ON guacamole_user.entity_id = guacamole_entity.entity_id - LEFT JOIN guacamole_user_history ON guacamole_user_history.user_id = guacamole_user.user_id WHERE guacamole_entity.name = #{username,jdbcType=VARCHAR} AND guacamole_entity.type = 'USER'::guacamole_entity_type