diff options
author | Morris Jobke <hey@morrisjobke.de> | 2014-05-19 01:21:37 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-05-19 01:21:37 +0200 |
commit | 804020bb6d7822a7010c3b8f95c25c2521b09a45 (patch) | |
tree | d8d0ec22414b17358d98a6665a5977e332aa7f18 /lib | |
parent | db9cfaa56dfaedf628755a7678249d24ad9f1ea5 (diff) | |
parent | f569c721a64486d0e7c7e307ed77ac0caed2dc2d (diff) | |
download | nextcloud-server-804020bb6d7822a7010c3b8f95c25c2521b09a45.tar.gz nextcloud-server-804020bb6d7822a7010c3b8f95c25c2521b09a45.zip |
Merge pull request #7363 from owncloud/optimize-startup-queries
Optimize some queries that are always executed when loading base.php
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/group/manager.php | 40 | ||||
-rw-r--r-- | lib/private/user/user.php | 12 |
2 files changed, 39 insertions, 13 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]; } /** diff --git a/lib/private/user/user.php b/lib/private/user/user.php index 229cbf68ff1..bc5c541e521 100644 --- a/lib/private/user/user.php +++ b/lib/private/user/user.php @@ -55,11 +55,6 @@ class User { */ public function __construct($uid, $backend, $emitter = null, $config = null) { $this->uid = $uid; - if ($backend and $backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) { - $this->displayName = $backend->getDisplayName($uid); - } else { - $this->displayName = $uid; - } $this->backend = $backend; $this->emitter = $emitter; $this->config = $config; @@ -86,6 +81,13 @@ class User { * @return string */ public function getDisplayName() { + if (!isset($this->displayName)) { + if ($this->backend and $this->backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) { + $this->displayName = $this->backend->getDisplayName($this->uid); + } else { + $this->displayName = $this->uid; + } + } return $this->displayName; } |