From f51935a25895a70652f4bd408ce7a5bfeb17acde Mon Sep 17 00:00:00 2001 From: Mathieu Moulin Date: Sat, 16 Nov 2024 18:10:08 +0100 Subject: [PATCH 1/2] Fix slow user card when many users in same group, disable loading of all other users (#31947) --- htdocs/user/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 50002e10a25e1..edb98825159fe 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -1940,7 +1940,7 @@ $exclude = array(); $usergroup = new UserGroup($db); - $groupslist = $usergroup->listGroupsForUser($object->id); + $groupslist = $usergroup->listGroupsForUser($object->id, false); if (!empty($groupslist)) { From a602309e04572e30cb95f9001cd159978c0b69b1 Mon Sep 17 00:00:00 2001 From: Mathieu Moulin Date: Sat, 16 Nov 2024 18:19:59 +0100 Subject: [PATCH 2/2] Fix user::load_previous_next_ref() with MULTICOMPANY_TRANSVERSE_MODE bad sql query (cartesian product replaced by INNER JOIN) (#31946) --- htdocs/core/class/commonobject.class.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index ee4a56eaa9c2c..0332a29c0ce90 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1891,7 +1891,9 @@ public function load_previous_next_ref($filter, $fieldid, $nodbprefix = 0) $sql = "SELECT MAX(te.".$fieldid.")"; $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + if (empty($user->admin) || !empty($user->entity) || $conf->entity != 1) { + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON ug.fk_user=te.rowid"; + } } if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) { $tmparray = explode('@', $this->ismultientitymanaged); @@ -1916,7 +1918,6 @@ public function load_previous_next_ref($filter, $fieldid, $nodbprefix = 0) if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) { $sql .= " AND te.entity IS NOT NULL"; // Show all users } else { - $sql .= " AND ug.fk_user = te.rowid"; $sql .= " AND ug.entity IN (".getEntity($this->element).")"; } } else { @@ -1944,7 +1945,9 @@ public function load_previous_next_ref($filter, $fieldid, $nodbprefix = 0) $sql = "SELECT MIN(te.".$fieldid.")"; $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + if (empty($user->admin) || !empty($user->entity) || $conf->entity != 1) { + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON ug.fk_user=te.rowid"; + } } if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) { $tmparray = explode('@', $this->ismultientitymanaged); @@ -1969,7 +1972,6 @@ public function load_previous_next_ref($filter, $fieldid, $nodbprefix = 0) if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) { $sql .= " AND te.entity IS NOT NULL"; // Show all users } else { - $sql .= " AND ug.fk_user = te.rowid"; $sql .= " AND ug.entity IN (".getEntity($this->element).")"; } } else {