From ede2aa236e0834fd4fac2ea59e7ef9c0a397ff06 Mon Sep 17 00:00:00 2001 From: macjohnny Date: Thu, 12 Jun 2014 09:41:23 +0200 Subject: [PATCH 1/4] Update manager.php add a function getUserGroupIds for retrieving group ids instead of group objects. this significantly improves performance when using many (nested) groups. --- lib/private/group/manager.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index dae6443e9d..150f4c1890 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -182,6 +182,18 @@ class Manager extends PublicEmitter { $this->cachedUserGroups[$uid] = array_values($groups); return $this->cachedUserGroups[$uid]; } + /** + * @param \OC\User\User $user + * @return array with group names + */ + public function getUserGroupIds($user) { + $groupIds = array(); + foreach ($this->backends as $backend) { + $groupIds = array_merge($groupIds,$backend->getUserGroups($user->getUID())); + + } + return $groupIds; + } /** * get a list of all display names in a group From 0af8aa689f128cbb930bed591f4ef79224049e83 Mon Sep 17 00:00:00 2001 From: macjohnny Date: Thu, 12 Jun 2014 09:51:23 +0200 Subject: [PATCH 2/4] drastic speedup for nested ldap groups Changes a function call in getUserGroups to only retrieve group ids instead of objects. this change significantly improves performance when using owncloud with many groups, e.g. nested ldap hierarchy (1.2.840.113556.1.4.1941), since getUserGroups gets called in oc_share::getItems, which is needed for every page request. in my particular case, it took more than 10s to load the calendar page and more than 6s to load the file page. this was in an environment with 100 user groups (nested) per user. The performance was bad due to the following call stack: self::getManager()->getUserGroups($user) - getGroupObject() (executed for every group!) - groupExists() (resulting in many ldap-requests) since the groups are loaded from ldap, it is unnecessary to check whether the group exists or not. --- lib/private/group.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/private/group.php b/lib/private/group.php index 8dc3812920..6bc6d78bba 100644 --- a/lib/private/group.php +++ b/lib/private/group.php @@ -187,12 +187,13 @@ class OC_Group { public static function getUserGroups($uid) { $user = self::$userManager->get($uid); if ($user) { - $groups = self::getManager()->getUserGroups($user); + /*$groups = self::getManager()->getUserGroups($user); $groupIds = array(); foreach ($groups as $group) { $groupIds[] = $group->getGID(); } - return $groupIds; + return $groupIds;*/ + return self::getManager()->getUserGroupIds($user); } else { return array(); } From b1094cfe82ffeaddd4d0cc9f241427d5d1b88ad2 Mon Sep 17 00:00:00 2001 From: macjohnny Date: Thu, 12 Jun 2014 11:28:57 +0200 Subject: [PATCH 3/4] Update group.php --- lib/private/group.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/private/group.php b/lib/private/group.php index 6bc6d78bba..bd9e3d37d1 100644 --- a/lib/private/group.php +++ b/lib/private/group.php @@ -187,12 +187,6 @@ class OC_Group { public static function getUserGroups($uid) { $user = self::$userManager->get($uid); if ($user) { - /*$groups = self::getManager()->getUserGroups($user); - $groupIds = array(); - foreach ($groups as $group) { - $groupIds[] = $group->getGID(); - } - return $groupIds;*/ return self::getManager()->getUserGroupIds($user); } else { return array(); From e8e2e47e6891276a260d465a4ef50c8ddc2ad8ce Mon Sep 17 00:00:00 2001 From: macjohnny Date: Thu, 12 Jun 2014 11:29:20 +0200 Subject: [PATCH 4/4] Update manager.php --- lib/private/group/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index 150f4c1890..3613c7547b 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -189,7 +189,7 @@ class Manager extends PublicEmitter { public function getUserGroupIds($user) { $groupIds = array(); foreach ($this->backends as $backend) { - $groupIds = array_merge($groupIds,$backend->getUserGroups($user->getUID())); + $groupIds = array_merge($groupIds, $backend->getUserGroups($user->getUID())); } return $groupIds;