Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Manager implements IManager {

public const MAX_TASK_AGE_SECONDS = 60 * 60 * 24 * 30 * 4; // 4 months

private const TASK_TYPES_CACHE_KEY = 'available_task_types_v2';
private const TASK_TYPES_CACHE_KEY = 'available_task_types_v3';
private const TASK_TYPE_IDS_CACHE_KEY = 'available_task_type_ids';

/** @var list<IProvider>|null */
Expand Down Expand Up @@ -122,6 +122,7 @@ public function __construct(
private IUserManager $userManager,
private IUserSession $userSession,
ICacheFactory $cacheFactory,
private IFactory $l10nFactory,
) {
$this->appData = $appDataFactory->get('core');
$this->distributedCache = $cacheFactory->createDistributed('task_processing::');
Expand Down Expand Up @@ -835,12 +836,15 @@ public function getPreferredProvider(string $taskTypeId) {
}

public function getAvailableTaskTypes(bool $showDisabled = false, ?string $userId = null): array {
// We cache by language, because some task type fields are translated
$cacheKey = self::TASK_TYPES_CACHE_KEY . ':' . $this->l10nFactory->findLanguage();

// userId will be obtained from the session if left to null
if (!$this->checkGuestAccess($userId)) {
return [];
}
if ($this->availableTaskTypes === null) {
$cachedValue = $this->distributedCache->get(self::TASK_TYPES_CACHE_KEY);
$cachedValue = $this->distributedCache->get($cacheKey);
if ($cachedValue !== null) {
$this->availableTaskTypes = unserialize($cachedValue);
}
Expand Down Expand Up @@ -886,7 +890,7 @@ public function getAvailableTaskTypes(bool $showDisabled = false, ?string $userI
}

$this->availableTaskTypes = $availableTaskTypes;
$this->distributedCache->set(self::TASK_TYPES_CACHE_KEY, serialize($this->availableTaskTypes), 60);
$this->distributedCache->set($cacheKey, serialize($this->availableTaskTypes), 60);
}


Expand Down
3 changes: 3 additions & 0 deletions tests/lib/TaskProcessing/TaskProcessingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Server;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\Events\GetTaskProcessingProvidersEvent;
Expand Down Expand Up @@ -620,6 +621,7 @@ protected function setUp(): void {
$userManager,
Server::get(IUserSession::class),
Server::get(ICacheFactory::class),
Server::get(IFactory::class),
);
}

Expand Down Expand Up @@ -1293,6 +1295,7 @@ private function createManagerInstance(): Manager {
Server::get(IUserManager::class),
Server::get(IUserSession::class),
Server::get(ICacheFactory::class),
Server::get(IFactory::class),
);
}

Expand Down
Loading