diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2022-04-05 21:38:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-05 21:38:03 +0200 |
commit | fde178b1be898a390ec86b08d320d650698990ac (patch) | |
tree | 520b0aec3c9d49e066650ac7a9c785214e992f48 | |
parent | fff26ad0069ddfa63b6882c5e14b7ed7b1c94f5a (diff) | |
parent | 9cb992e93c7c0fbf816323381f8ee082cf3f073f (diff) | |
download | nextcloud-server-fde178b1be898a390ec86b08d320d650698990ac.tar.gz nextcloud-server-fde178b1be898a390ec86b08d320d650698990ac.zip |
Merge pull request #31849 from nextcloud/fix/cache-account
-rw-r--r-- | lib/private/Accounts/AccountManager.php | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 127adc9ef38..5792ba1dc5d 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -41,6 +41,7 @@ use libphonenumber\PhoneNumber; use libphonenumber\PhoneNumberFormat; use libphonenumber\PhoneNumberUtil; use OC\Profile\TProfileHelper; +use OC\Cache\CappedMemoryCache; use OCA\Settings\BackgroundJobs\VerifyUserData; use OCP\Accounts\IAccount; use OCP\Accounts\IAccountManager; @@ -116,6 +117,7 @@ class AccountManager implements IAccountManager { private $crypto; /** @var IFactory */ private $l10nfactory; + private CappedMemoryCache $internalCache; public function __construct( IDBConnection $connection, @@ -142,6 +144,7 @@ class AccountManager implements IAccountManager { $this->crypto = $crypto; // DIing IL10N results in a dependency loop $this->l10nfactory = $factory; + $this->internalCache = new CappedMemoryCache(); } /** @@ -763,7 +766,12 @@ class AccountManager implements IAccountManager { } public function getAccount(IUser $user): IAccount { - return $this->parseAccountData($user, $this->getUser($user)); + if ($this->internalCache->hasKey($user->getUID())) { + return $this->internalCache->get($user->getUID()); + } + $account = $this->parseAccountData($user, $this->getUser($user)); + $this->internalCache->set($user->getUID(), $account); + return $account; } public function updateAccount(IAccount $account): void { @@ -813,5 +821,6 @@ class AccountManager implements IAccountManager { } $this->updateUser($account->getUser(), $data, true); + $this->internalCache->set($account->getUser()->getUID(), $account); } } |