Skip to content

Commit fde178b

Browse files
authored
Merge pull request #31849 from nextcloud/fix/cache-account
2 parents fff26ad + 9cb992e commit fde178b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/private/Accounts/AccountManager.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use libphonenumber\PhoneNumberFormat;
4242
use libphonenumber\PhoneNumberUtil;
4343
use OC\Profile\TProfileHelper;
44+
use OC\Cache\CappedMemoryCache;
4445
use OCA\Settings\BackgroundJobs\VerifyUserData;
4546
use OCP\Accounts\IAccount;
4647
use OCP\Accounts\IAccountManager;
@@ -116,6 +117,7 @@ class AccountManager implements IAccountManager {
116117
private $crypto;
117118
/** @var IFactory */
118119
private $l10nfactory;
120+
private CappedMemoryCache $internalCache;
119121

120122
public function __construct(
121123
IDBConnection $connection,
@@ -142,6 +144,7 @@ public function __construct(
142144
$this->crypto = $crypto;
143145
// DIing IL10N results in a dependency loop
144146
$this->l10nfactory = $factory;
147+
$this->internalCache = new CappedMemoryCache();
145148
}
146149

147150
/**
@@ -763,7 +766,12 @@ private function parseAccountData(IUser $user, $data): Account {
763766
}
764767

765768
public function getAccount(IUser $user): IAccount {
766-
return $this->parseAccountData($user, $this->getUser($user));
769+
if ($this->internalCache->hasKey($user->getUID())) {
770+
return $this->internalCache->get($user->getUID());
771+
}
772+
$account = $this->parseAccountData($user, $this->getUser($user));
773+
$this->internalCache->set($user->getUID(), $account);
774+
return $account;
767775
}
768776

769777
public function updateAccount(IAccount $account): void {
@@ -813,5 +821,6 @@ public function updateAccount(IAccount $account): void {
813821
}
814822

815823
$this->updateUser($account->getUser(), $data, true);
824+
$this->internalCache->set($account->getUser()->getUID(), $account);
816825
}
817826
}

0 commit comments

Comments
 (0)