Update manager.php

This commit is contained in:
macjohnny 2014-06-19 19:35:10 +02:00
parent c954168973
commit 14fcd68172
1 changed files with 25 additions and 9 deletions

View File

@ -47,6 +47,12 @@ class Manager extends PublicEmitter {
*/ */
private $cachedUserGroups = array(); private $cachedUserGroups = array();
/**
* @var string[]
*/
private $cachedUserGroupIds = array();
/** /**
* @param \OC\User\Manager $userManager * @param \OC\User\Manager $userManager
*/ */
@ -176,7 +182,7 @@ class Manager extends PublicEmitter {
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
$groupIds = $backend->getUserGroups($uid); $groupIds = $backend->getUserGroups($uid);
foreach ($groupIds as $groupId) { foreach ($groupIds as $groupId) {
$groups[$groupId] = $this->get($groupId); $groups[] = $this->get($groupId);
} }
} }
$this->cachedUserGroups[$uid] = $groups; $this->cachedUserGroups[$uid] = $groups;
@ -186,18 +192,28 @@ class Manager extends PublicEmitter {
/** /**
* get a list of group ids for a user * get a list of group ids for a user
* @param \OC\User\User $user * @param \OC\User\User $user
* @return array with group names * @return array with group ids
*/ */
public function getUserGroupIds($user) { public function getUserGroupIds($user) {
$uid = $user->getUID();
if (isset($this->cachedUserGroups[$uid])) {
return array_keys($this->cachedUserGroups[$uid]);
}
$groupIds = array(); $groupIds = array();
foreach ($this->backends as $backend) { $userId = $user->getUID();
$groupIds = array_merge($groupIds, $backend->getUserGroups($user->getUID())); if (isset($this->cachedUserGroupIds[$userId])) {
return $this->cachedUserGroupIds[$userId];
} }
return $groupIds; if (isset($this->cachedUserGroups[$userId])) {
foreach($this->cachedUserGroups[$userId] as $group)
{
$groupIds[] = $group->getGID();
}
}
else
{
foreach ($this->backends as $backend) {
$groupIds = array_merge($groupIds, $backend->getUserGroups($userId));
}
}
$this->cachedUserGroupIds[$userId] = $groupIds;
return $this->cachedUserGroupIds[$userId];
} }
/** /**