aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-02-02 15:45:34 +0100
committerJoas Schilling <coding@schilljs.com>2021-02-15 10:36:08 +0100
commit645f83121eb9bdc936c404ac8dbad346c2b934e3 (patch)
tree4556c7b6e70064271ec8f49176a7fd5545d86cea /lib/private
parentb418a680e7431dd39acfdc1c52c693ae777a8c83 (diff)
downloadnextcloud-server-645f83121eb9bdc936c404ac8dbad346c2b934e3.tar.gz
nextcloud-server-645f83121eb9bdc936c404ac8dbad346c2b934e3.zip
Cache the user backend info for 300s
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/User/Manager.php25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php
index e447b0bfcf2..036d2703d35 100644
--- a/lib/private/User/Manager.php
+++ b/lib/private/User/Manager.php
@@ -38,6 +38,8 @@ use OC\HintException;
use OC\Hooks\PublicEmitter;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\ICache;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IUser;
@@ -84,14 +86,19 @@ class Manager extends PublicEmitter implements IUserManager {
/** @var EventDispatcherInterface */
private $dispatcher;
+ /** @var ICache */
+ private $cache;
+
/** @var IEventDispatcher */
private $eventDispatcher;
public function __construct(IConfig $config,
EventDispatcherInterface $oldDispatcher,
+ ICacheFactory $cacheFactory,
IEventDispatcher $eventDispatcher) {
$this->config = $config;
$this->dispatcher = $oldDispatcher;
+ $this->cache = $cacheFactory->createDistributed('user_backend_map');
$cachedUsers = &$this->cachedUsers;
$this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
/** @var \OC\User\User $user */
@@ -150,8 +157,24 @@ class Manager extends PublicEmitter implements IUserManager {
if (isset($this->cachedUsers[$uid])) { //check the cache first to prevent having to loop over the backends
return $this->cachedUsers[$uid];
}
- foreach ($this->backends as $backend) {
+
+ $cachedBackend = $this->cache->get($uid);
+ if ($cachedBackend !== null && isset($this->backends[$cachedBackend])) {
+ // Cache has the info of the user backend already, so ask that one directly
+ $backend = $this->backends[$cachedBackend];
+ if ($backend->userExists($uid)) {
+ return $this->getUserObject($uid, $backend);
+ }
+ }
+
+ foreach ($this->backends as $i => $backend) {
+ if ($i === $cachedBackend) {
+ // Tried that one already
+ continue;
+ }
+
if ($backend->userExists($uid)) {
+ $this->cache->set($uid, $i, 300);
return $this->getUserObject($uid, $backend);
}
}