From 76af70180d4b3f533e957bd55a134ad1018dc815 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 28 Apr 2016 12:03:19 +0200 Subject: Don't loop over the backends, we already know where the user should be --- lib/private/user/manager.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php index 7967f877024..8758a4667f5 100644 --- a/lib/private/user/manager.php +++ b/lib/private/user/manager.php @@ -335,11 +335,11 @@ class Manager extends PublicEmitter implements IUserManager { $offset = 0; do { $users = $backend->getUsers($search, $limit, $offset); - foreach ($users as $user) { - $user = $this->get($user); - if (is_null($user)) { + foreach ($users as $uid) { + if (!$backend->userExists($uid)) { continue; } + $user = $this->getUserObject($uid, $backend); $return = $callback($user); if ($return === false) { break; -- cgit v1.2.3 From b8114bcc33f78160b298d7a338a6a680d5ee077e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 28 Apr 2016 12:26:48 +0200 Subject: When we iterate over all users that might be too much memory --- lib/private/user/manager.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php index 8758a4667f5..4371be134aa 100644 --- a/lib/private/user/manager.php +++ b/lib/private/user/manager.php @@ -147,14 +147,19 @@ class Manager extends PublicEmitter implements IUserManager { * * @param string $uid * @param \OCP\UserInterface $backend + * @param bool $cacheUser If false the newly created user object will not be cached * @return \OC\User\User */ - protected function getUserObject($uid, $backend) { + protected function getUserObject($uid, $backend, $cacheUser = true) { if (isset($this->cachedUsers[$uid])) { return $this->cachedUsers[$uid]; } - $this->cachedUsers[$uid] = new User($uid, $backend, $this, $this->config); - return $this->cachedUsers[$uid]; + + $user = new User($uid, $backend, $this, $this->config); + if ($cacheUser) { + $this->cachedUsers[$uid] = $user; + } + return $user; } /** @@ -339,7 +344,7 @@ class Manager extends PublicEmitter implements IUserManager { if (!$backend->userExists($uid)) { continue; } - $user = $this->getUserObject($uid, $backend); + $user = $this->getUserObject($uid, $backend, false); $return = $callback($user); if ($return === false) { break; -- cgit v1.2.3