Browse Source

Cache ConfigProfile

Reduce DB query count on homepage from 21 to 13

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
tags/v25.0.0beta3
Carl Schwan 1 year ago
parent
commit
5edab8c922
No account linked to committer's email address
1 changed files with 8 additions and 1 deletions
  1. 8
    1
      lib/private/Profile/ProfileManager.php

+ 8
- 1
lib/private/Profile/ProfileManager.php View File

use OCP\IUser; use OCP\IUser;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
use OCP\Profile\ILinkAction; use OCP\Profile\ILinkAction;
use OCP\Cache\CappedMemoryCache;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;




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


private const CORE_APP_ID = 'core'; private const CORE_APP_ID = 'core';


$this->l10nFactory = $l10nFactory; $this->l10nFactory = $l10nFactory;
$this->logger = $logger; $this->logger = $logger;
$this->coordinator = $coordinator; $this->coordinator = $coordinator;
$this->configCache = new CappedMemoryCache();
} }


/** /**
public function getProfileConfig(IUser $targetUser, ?IUser $visitingUser): array { public function getProfileConfig(IUser $targetUser, ?IUser $visitingUser): array {
$defaultProfileConfig = $this->getDefaultProfileConfig($targetUser, $visitingUser); $defaultProfileConfig = $this->getDefaultProfileConfig($targetUser, $visitingUser);
try { 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 // Merge defaults with the existing config in case the defaults are missing
$config->setConfigArray(array_merge( $config->setConfigArray(array_merge(
$defaultProfileConfig, $defaultProfileConfig,

Loading…
Cancel
Save