Skip to content

Commit d8aad5f

Browse files
committed
Cache account information
Currently, each field of the profile settings is fetching the account information. This patch makes it so that only the first time do a DB call and all the later ones are cached. Reduce by 5 queries when loading the profile setting page and I suppose other pages are affected since loading a page generates always fetch at least once the account information to see if the profile feature is enabled for the user. Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 9c84aa5 commit d8aad5f

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($user->getUID(), $account);
816825
}
817826
}

0 commit comments

Comments
 (0)