Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/private/App/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\App\IAppManager;
use OCP\App\ManagerEvent;
use OCP\BackgroundJob\IJobList;
use OCP\Cache\CappedMemoryCache;
use OCP\Collaboration\AutoComplete\IManager as IAutoCompleteManager;
use OCP\Collaboration\Collaborators\ISearch as ICollaboratorSearch;
use OCP\Diagnostics\IEventLogger;
Expand Down Expand Up @@ -61,6 +62,7 @@ class AppManager implements IAppManager {

/** @var string[] $appId => $enabled */
private array $enabledAppsCache = [];
private CappedMemoryCache $enabledAppsForUserCache;

/** @var array<string, array{path: string, url: string}> $appId => approot information */
private array $appsDirCache = [];
Expand Down Expand Up @@ -108,6 +110,7 @@ public function __construct(
private ConfigManager $configManager,
private DependencyAnalyzer $dependencyAnalyzer,
) {
$this->enabledAppsForUserCache = new CappedMemoryCache();
}

private function getNavigationManager(): INavigationManager {
Expand Down Expand Up @@ -241,11 +244,15 @@ public function getAllAppsInAppsFolders(): array {
*/
#[\Override]
public function getEnabledAppsForUser(IUser $user) {
$uid = $user->getUID();
if (isset($this->enabledAppsForUserCache[$uid])) {
return $this->enabledAppsForUserCache[$uid];
}
$apps = $this->getEnabledAppsValues();
$appsForUser = array_filter($apps, function ($enabled) use ($user) {
return $this->checkAppForUser($enabled, $user);
});
return array_keys($appsForUser);
return $this->enabledAppsForUserCache[$uid] = array_keys($appsForUser);
}

#[\Override]
Expand Down Expand Up @@ -648,6 +655,7 @@ public function enableApp(string $appId, bool $forceEnable = false): void {
}

$this->enabledAppsCache[$appId] = 'yes';
$this->enabledAppsForUserCache = new CappedMemoryCache();
$this->getAppConfig()->setValue($appId, 'enabled', 'yes');
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId));
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
Expand Down Expand Up @@ -704,6 +712,7 @@ public function enableAppForGroups(string $appId, array $groups, bool $forceEnab
}, $groups);

$this->enabledAppsCache[$appId] = json_encode($groupIds);
$this->enabledAppsForUserCache = new CappedMemoryCache();
$this->getAppConfig()->setValue($appId, 'enabled', json_encode($groupIds));
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId, $groupIds));
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent(
Expand Down Expand Up @@ -736,6 +745,7 @@ public function disableApp($appId, $automaticDisabled = false): void {
}

unset($this->enabledAppsCache[$appId]);
$this->enabledAppsForUserCache = new CappedMemoryCache();
$this->getAppConfig()->setValue($appId, 'enabled', 'no');

// run uninstall steps
Expand Down
Loading