Skip to content

Commit

Permalink
fix(taskprocessing): Cache result of getAvailableTaskTypes between re…
Browse files Browse the repository at this point in the history
…quests

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Jan 23, 2025
1 parent 42c021f commit 258df9e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Http\Client\IClientService;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IServerContainer;
Expand Down Expand Up @@ -77,6 +79,8 @@ class Manager implements IManager {
private ?array $availableTaskTypes = null;

private IAppData $appData;
private ICache $cache;

public function __construct(
private IConfig $config,
private Coordinator $coordinator,
Expand All @@ -91,8 +95,10 @@ public function __construct(
private IUserMountCache $userMountCache,
private IClientService $clientService,
private IAppManager $appManager,
ICacheFactory $cacheFactory,
) {
$this->appData = $appDataFactory->get('core');
$this->cache = $cacheFactory->createLocal('task_processing::');
}


Expand Down Expand Up @@ -582,10 +588,10 @@ private function _getTaskTypeSettings(): array {
foreach ($taskTypes as $taskType) {
$taskTypeSettings[$taskType->getId()] = false;
};

return $taskTypeSettings;
}

}

/**
Expand Down Expand Up @@ -746,6 +752,9 @@ public function getPreferredProvider(string $taskTypeId) {
}

public function getAvailableTaskTypes(bool $showDisabled = false): array {
if ($this->availableTaskTypes === null) {
$this->availableTaskTypes = $this->cache->get('available_task_types');
}
// Either we have no cache or showDisabled is turned on, which we don't want to cache, ever.
if ($this->availableTaskTypes === null || $showDisabled) {
$taskTypes = $this->_getTaskTypes();
Expand Down Expand Up @@ -787,6 +796,7 @@ public function getAvailableTaskTypes(bool $showDisabled = false): array {
}

$this->availableTaskTypes = $availableTaskTypes;
$this->cache->set('available_task_types', $this->availableTaskTypes, 60);
}


Expand Down

0 comments on commit 258df9e

Please sign in to comment.