Skip to content

Commit

Permalink
Merge pull request #33595 from nextcloud/fix/cache-profile-config
Browse files Browse the repository at this point in the history
Cache ConfigProfile
  • Loading branch information
CarlSchwan authored Aug 23, 2022
2 parents 385f3c0 + 5edab8c commit 232866d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/private/Profile/ProfileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCP\IUser;
use OCP\L10N\IFactory;
use OCP\Profile\ILinkAction;
use OCP\Cache\CappedMemoryCache;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -81,6 +82,8 @@ class ProfileManager {

/** @var null|ILinkAction[] */
private $sortedActions = null;
/** @var CappedMemoryCache<ProfileConfig> */
private CappedMemoryCache $configCache;

private const CORE_APP_ID = 'core';

Expand Down Expand Up @@ -127,6 +130,7 @@ public function __construct(
$this->l10nFactory = $l10nFactory;
$this->logger = $logger;
$this->coordinator = $coordinator;
$this->configCache = new CappedMemoryCache();
}

/**
Expand Down Expand Up @@ -370,7 +374,10 @@ private function getDefaultProfileConfig(IUser $targetUser, ?IUser $visitingUser
public function getProfileConfig(IUser $targetUser, ?IUser $visitingUser): array {
$defaultProfileConfig = $this->getDefaultProfileConfig($targetUser, $visitingUser);
try {
$config = $this->configMapper->get($targetUser->getUID());
if (($config = $this->configCache[$targetUser->getUID()]) === null) {
$config = $this->configMapper->get($targetUser->getUID());
$this->configCache[$targetUser->getUID()] = $config;
}
// Merge defaults with the existing config in case the defaults are missing
$config->setConfigArray(array_merge(
$defaultProfileConfig,
Expand Down

0 comments on commit 232866d

Please sign in to comment.