Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drastic ldap speedup (update) #9104

Merged
merged 9 commits into from Oct 17, 2014
Merged
45 changes: 37 additions & 8 deletions lib/private/group/manager.php
Expand Up @@ -47,31 +47,45 @@ class Manager extends PublicEmitter {
*/
private $cachedUserGroups = array();

/**
* @var string[]
*/
private $cachedUserGroupIds = array();


/**
* @param \OC\User\Manager $userManager
*/
public function __construct($userManager) {
$this->userManager = $userManager;
$cachedGroups = & $this->cachedGroups;
$cachedUserGroups = & $this->cachedUserGroups;
$this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) {
$cachedUserGroupIds = & $this->cachedUserGroupIds;
$this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups, &$cachedUserGroupIds) {
/**
* @var \OC\Group\Group $group
*/
unset($cachedGroups[$group->getGID()]);
$cachedUserGroups = array();
$Position = array_search($group->getGID(), $cachedUserGroupIds);
if($Position !== false)
{
unset($cachedUserGroupIds[$Position]);
}
});
$this->listen('\OC\Group', 'postAddUser', function ($group) use (&$cachedUserGroups) {
$this->listen('\OC\Group', 'postAddUser', function ($group) use (&$cachedUserGroups, &$cachedUserGroupIds) {
/**
* @var \OC\Group\Group $group
*/
$cachedUserGroups = array();
$cachedUserGroupIds = array();
});
$this->listen('\OC\Group', 'postRemoveUser', function ($group) use (&$cachedUserGroups) {
$this->listen('\OC\Group', 'postRemoveUser', function ($group) use (&$cachedUserGroups, &$cachedUserGroupIds) {
/**
* @var \OC\Group\Group $group
*/
$cachedUserGroups = array();
$cachedUserGroupIds = array();
});
}

Expand Down Expand Up @@ -182,17 +196,32 @@ public function getUserGroups($user) {
$this->cachedUserGroups[$uid] = array_values($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->cachedUserGroupIds[$userId])) {
return $this->cachedUserGroupIds[$userId];
}
if (isset($this->cachedUserGroups[$userId])) {
foreach($this->cachedUserGroups[$userId] as $group)
{
$groupIds[] = $group->getGID();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brackets and else in the same line please

else
{
foreach ($this->backends as $backend) {
$groupIds = array_merge($groupIds, $backend->getUserGroups($userId));
}
}
return $groupIds;
$this->cachedUserGroupIds[$userId] = $groupIds;
return $this->cachedUserGroupIds[$userId];
}

/**
Expand Down