diff options
author | Joas Schilling <coding@schilljs.com> | 2022-02-26 00:34:17 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-02-28 13:49:12 +0100 |
commit | b90e657ac7b0760aecffeadf046908131053d6bf (patch) | |
tree | 9ad4b1b72f2f3e45018e6819944c7bbfe7f4f382 | |
parent | c203bc71ada7da3642c8465b3ffc2cd80eea6743 (diff) | |
download | nextcloud-server-b90e657ac7b0760aecffeadf046908131053d6bf.tar.gz nextcloud-server-b90e657ac7b0760aecffeadf046908131053d6bf.zip |
Delay loading user preferences until we need them
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/private/User/User.php | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/private/User/User.php b/lib/private/User/User.php index 5fa1272f95c..0a51622428b 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -73,7 +73,7 @@ class User implements IUser { /** @var IEventDispatcher */ private $dispatcher; - /** @var bool */ + /** @var bool|null */ private $enabled; /** @var Emitter|Manager */ @@ -82,7 +82,7 @@ class User implements IUser { /** @var string */ private $home; - /** @var int */ + /** @var int|null */ private $lastLogin; /** @var \OCP\IConfig */ @@ -104,9 +104,6 @@ class User implements IUser { } $this->config = $config; $this->urlGenerator = $urlGenerator; - $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true'); - $this->enabled = ($enabled === 'true'); - $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0); if (is_null($this->urlGenerator)) { $this->urlGenerator = \OC::$server->getURLGenerator(); } @@ -231,14 +228,17 @@ class User implements IUser { * @return int */ public function getLastLogin() { - return $this->lastLogin; + if ($this->lastLogin === null) { + $this->lastLogin = (int) $this->config->getUserValue($this->uid, 'login', 'lastLogin', 0); + } + return (int) $this->lastLogin; } /** * updates the timestamp of the most recent login of this user */ public function updateLastLoginTimestamp() { - $firstTimeLogin = ($this->lastLogin === 0); + $firstTimeLogin = ($this->getLastLogin() === 0); $this->lastLogin = time(); $this->config->setUserValue( $this->uid, 'login', 'lastLogin', $this->lastLogin); @@ -406,7 +406,11 @@ class User implements IUser { * @return bool */ public function isEnabled() { - return $this->enabled; + if ($this->enabled === null) { + $enabled = $this->config->getUserValue($this->uid, 'core', 'enabled', 'true'); + $this->enabled = $enabled === 'true'; + } + return (bool) $this->enabled; } /** |