diff options
author | Morris Jobke <hey@morrisjobke.de> | 2014-05-19 03:21:37 +0400 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-05-19 03:21:37 +0400 |
commit | 804020bb6d7822a7010c3b8f95c25c2521b09a45 (patch) | |
tree | d8d0ec22414b17358d98a6665a5977e332aa7f18 /lib/private/group | |
parent | db9cfaa56dfaedf628755a7678249d24ad9f1ea5 (diff) | |
parent | f569c721a64486d0e7c7e307ed77ac0caed2dc2d (diff) |
Merge pull request #7363 from owncloud/optimize-startup-queries
Optimize some queries that are always executed when loading base.php
Diffstat (limited to 'lib/private/group')
-rw-r--r-- | lib/private/group/manager.php | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index f03f7004132..707009fb3d4 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -40,19 +40,38 @@ class Manager extends PublicEmitter { /** * @var \OC\Group\Group[] */ - private $cachedGroups; + private $cachedGroups = array(); + + /** + * @var \OC\Group\Group[] + */ + private $cachedUserGroups = array(); /** * @param \OC\User\Manager $userManager */ public function __construct($userManager) { $this->userManager = $userManager; - $cache = & $this->cachedGroups; - $this->listen('\OC\Group', 'postDelete', function ($group) use (&$cache) { + $cachedGroups = & $this->cachedGroups; + $cachedUserGroups = & $this->cachedUserGroups; + $this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) { + /** + * @var \OC\Group\Group $group + */ + unset($cachedGroups[$group->getGID()]); + $cachedUserGroups = array(); + }); + $this->listen('\OC\Group', 'postAddUser', function ($group) use (&$cachedUserGroups) { /** * @var \OC\Group\Group $group */ - unset($cache[$group->getGID()]); + $cachedUserGroups = array(); + }); + $this->listen('\OC\Group', 'postRemoveUser', function ($group) use (&$cachedUserGroups) { + /** + * @var \OC\Group\Group $group + */ + $cachedUserGroups = array(); }); } @@ -135,7 +154,7 @@ class Manager extends PublicEmitter { foreach ($this->backends as $backend) { $groupIds = $backend->getGroups($search, $limit, $offset); foreach ($groupIds as $groupId) { - $groups[$groupId] = $this->getGroupObject($groupId); + $groups[$groupId] = $this->get($groupId); } if (!is_null($limit) and $limit <= 0) { return array_values($groups); @@ -149,14 +168,19 @@ class Manager extends PublicEmitter { * @return \OC\Group\Group[] */ public function getUserGroups($user) { + $uid = $user->getUID(); + if (isset($this->cachedUserGroups[$uid])) { + return $this->cachedUserGroups[$uid]; + } $groups = array(); foreach ($this->backends as $backend) { - $groupIds = $backend->getUserGroups($user->getUID()); + $groupIds = $backend->getUserGroups($uid); foreach ($groupIds as $groupId) { - $groups[$groupId] = $this->getGroupObject($groupId); + $groups[$groupId] = $this->get($groupId); } } - return array_values($groups); + $this->cachedUserGroups[$uid] = array_values($groups); + return $this->cachedUserGroups[$uid]; } /** |