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: 8 additions & 2 deletions lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Manager implements IManager {
public const LEGACY_PREFIX_TEXTTOIMAGE = 'legacy:TextToImage:';
public const LEGACY_PREFIX_SPEECHTOTEXT = 'legacy:SpeechToText:';

public const TASK_TYPES_CACHE_KEY = 'available_task_types_v3';

/** @var list<IProvider>|null */
private ?array $providers = null;

Expand Down Expand Up @@ -98,6 +100,7 @@ public function __construct(
private IClientService $clientService,
private IAppManager $appManager,
ICacheFactory $cacheFactory,
private IFactory $l10nFactory,
) {
$this->appData = $appDataFactory->get('core');
$this->distributedCache = $cacheFactory->createDistributed('task_processing::');
Expand Down Expand Up @@ -738,8 +741,11 @@ public function getPreferredProvider(string $taskTypeId) {
}

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

if ($this->availableTaskTypes === null) {
$cachedValue = $this->distributedCache->get('available_task_types_v2');
$cachedValue = $this->distributedCache->get($cacheKey);
if ($cachedValue !== null) {
$this->availableTaskTypes = unserialize($cachedValue);
}
Expand Down Expand Up @@ -775,7 +781,7 @@ public function getAvailableTaskTypes(): array {
}

$this->availableTaskTypes = $availableTaskTypes;
$this->distributedCache->set('available_task_types_v2', serialize($this->availableTaskTypes), 60);
$this->distributedCache->set($cacheKey, serialize($this->availableTaskTypes), 60);
}

return $this->availableTaskTypes;
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/TaskProcessing/TaskProcessingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCP\IServerContainer;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\Events\TaskFailedEvent;
use OCP\TaskProcessing\Events\TaskSuccessfulEvent;
Expand Down Expand Up @@ -478,6 +479,7 @@ protected function setUp(): void {
\OC::$server->get(IClientService::class),
\OC::$server->get(IAppManager::class),
\OC::$server->get(ICacheFactory::class),
\OC::$server->get(IFactory::class),
);
}

Expand Down
Loading