summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-05-31 17:42:51 +0200
committerRobin Appelman <icewind@owncloud.com>2013-05-31 17:42:51 +0200
commitf00844a003a7d08588a56fcee6914f5e1d885ea3 (patch)
tree9dd8a759b412387d98798800819dc9886c9a219b
parenta8fb8033192d2a1129955989a0150058b3490883 (diff)
downloadnextcloud-server-f00844a003a7d08588a56fcee6914f5e1d885ea3.tar.gz
nextcloud-server-f00844a003a7d08588a56fcee6914f5e1d885ea3.zip
fix caching of user objects
-rw-r--r--lib/user/manager.php27
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/user/manager.php b/lib/user/manager.php
index a4639c3f2cc..3b6d4bcfe55 100644
--- a/lib/user/manager.php
+++ b/lib/user/manager.php
@@ -32,6 +32,16 @@ class Manager extends PublicEmitter {
private $cachedUsers = array();
+ public function __construct() {
+ $cachedUsers = $this->cachedUsers;
+ $this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
+ $i = array_search($user, $cachedUsers);
+ if ($i !== false) {
+ unset($cachedUsers[$i]);
+ }
+ });
+ }
+
/**
* @param \OC_User_Backend $backend
*/
@@ -62,13 +72,20 @@ class Manager extends PublicEmitter {
}
foreach ($this->backends as $backend) {
if ($backend->userExists($uid)) {
- $this->cachedUsers[$uid] = new User($uid, $backend, $this);
- return $this->cachedUsers[$uid];
+ return $this->getUserObject($uid, $backend);
}
}
return null;
}
+ protected function getUserObject($uid, $backend) {
+ if (isset($this->cachedUsers[$uid])) {
+ return $this->cachedUsers[$uid];
+ }
+ $this->cachedUsers[$uid] = new User($uid, $backend, $this);
+ return $this->cachedUsers[$uid];
+ }
+
/**
* @param string $uid
* @return bool
@@ -96,7 +113,7 @@ class Manager extends PublicEmitter {
$backendUsers = $backend->getUsers($pattern, $limit, $offset);
if (is_array($backendUsers)) {
foreach ($backendUsers as $uid) {
- $users[] = $this->get($uid);
+ $users[] = $this->getUserObject($uid, $backend);
if (!is_null($limit)) {
$limit--;
}
@@ -132,7 +149,7 @@ class Manager extends PublicEmitter {
$backendUsers = $backend->getDisplayNames($pattern, $limit, $offset);
if (is_array($backendUsers)) {
foreach ($backendUsers as $uid => $displayName) {
- $users[] = $this->get($uid);
+ $users[] = $this->getUserObject($uid, $backend);
if (!is_null($limit)) {
$limit--;
}
@@ -185,7 +202,7 @@ class Manager extends PublicEmitter {
foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC_USER_BACKEND_CREATE_USER)) {
$backend->createUser($uid, $password);
- $user = $this->get($uid);
+ $user = $this->getUserObject($uid, $backend);
$this->emit('\OC\User', 'postCreateUser', array($user, $password));
return $user;
}