Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-04-05 19:57:55 +0300
committerCarl Schwan <carl@carlschwan.eu>2022-04-05 20:29:54 +0300
commit9cb992e93c7c0fbf816323381f8ee082cf3f073f (patch)
treee2bf00ec4d7361a82600bf051ff5286436536168
parent9c84aa5870204a871024ca18b4994ed40defdd9b (diff)
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>
-rw-r--r--lib/private/Accounts/AccountManager.php11
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);
}
}