clean up function getUserGroupIds

clean up of function getUserGroupIds and improved caching mechanism of cachedUserGroupIds
This commit is contained in:
macjohnny 2014-06-23 14:47:19 +02:00
parent 405e89f45a
commit 24e397afd2
1 changed files with 4 additions and 7 deletions

View File

@ -68,8 +68,7 @@ class Manager extends PublicEmitter {
unset($cachedGroups[$group->getGID()]); unset($cachedGroups[$group->getGID()]);
$cachedUserGroups = array(); $cachedUserGroups = array();
$Position = array_search($group->getGID(), $cachedUserGroupIds); $Position = array_search($group->getGID(), $cachedUserGroupIds);
if($Position !== false) if($Position !== false) {
{
unset($cachedUserGroupIds[$Position]); unset($cachedUserGroupIds[$Position]);
} }
}); });
@ -194,6 +193,7 @@ class Manager extends PublicEmitter {
} }
} }
$this->cachedUserGroups[$uid] = array_values($groups); $this->cachedUserGroups[$uid] = array_values($groups);
$this->cachedUserGroupIds[$uid] = array_keys($groups);
return $this->cachedUserGroups[$uid]; return $this->cachedUserGroups[$uid];
} }
@ -209,13 +209,10 @@ class Manager extends PublicEmitter {
return $this->cachedUserGroupIds[$userId]; return $this->cachedUserGroupIds[$userId];
} }
if (isset($this->cachedUserGroups[$userId])) { if (isset($this->cachedUserGroups[$userId])) {
foreach($this->cachedUserGroups[$userId] as $group) foreach($this->cachedUserGroups[$userId] as $group) {
{
$groupIds[] = $group->getGID(); $groupIds[] = $group->getGID();
} }
} } else {
else
{
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
$groupIds = array_merge($groupIds, $backend->getUserGroups($userId)); $groupIds = array_merge($groupIds, $backend->getUserGroups($userId));
} }