From 174ab07a4beed45b2d3a477723f6b47a37ecc7ce Mon Sep 17 00:00:00 2001 From: macjohnny Date: Thu, 19 Jun 2014 11:37:46 +0200 Subject: backport of #9104 Update manager.php add caching to getUserGroupIds Update manager.php added description and blank lines in getUserGroupIds Update manager.php defined $uid in getUserGroupIds Update manager.php Update manager.php Update manager.php clean up function getUserGroupIds clean up of function getUserGroupIds and improved caching mechanism of cachedUserGroupIds modified caching mechanism in getUserGroupIds removed cachedUserGroupIds, instead changed indexing in getUserGroups to groupId adapted tests for a groupId indexed group array --- lib/private/group/manager.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index 58a23924872..816e7b427f5 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -48,6 +48,7 @@ class Manager extends PublicEmitter implements IGroupManager { */ private $cachedUserGroups = array(); + /** * @param \OC\User\Manager $userManager */ @@ -180,18 +181,24 @@ class Manager extends PublicEmitter implements IGroupManager { $groups[$groupId] = $this->get($groupId); } } - $this->cachedUserGroups[$uid] = array_values($groups); + $this->cachedUserGroups[$uid] = $groups; return $this->cachedUserGroups[$uid]; } + /** + * get a list of group ids for a user * @param \OC\User\User $user - * @return array with group names + * @return array with group ids */ public function getUserGroupIds($user) { $groupIds = array(); - foreach ($this->backends as $backend) { - $groupIds = array_merge($groupIds, $backend->getUserGroups($user->getUID())); - + $userId = $user->getUID(); + if (isset($this->cachedUserGroups[$userId])) { + return array_keys($this->cachedUserGroups[$userId]); + } else { + foreach ($this->backends as $backend) { + $groupIds = array_merge($groupIds, $backend->getUserGroups($userId)); + } } return $groupIds; } -- cgit v1.2.3