fix(TaskProcessing): Cache task types by user language

fixes https://github.com/nextcloud/assistant/issues/357

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
pull/55168/head
Marcel Klehr 2025-09-17 11:05:28 +07:00
parent 4d06a922b9
commit 984f6023aa
2 changed files with 10 additions and 2 deletions

@ -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;
@ -98,6 +100,7 @@ class Manager implements IManager {
private IClientService $clientService,
private IAppManager $appManager,
ICacheFactory $cacheFactory,
private IFactory $l10nFactory,
) {
$this->appData = $appDataFactory->get('core');
$this->distributedCache = $cacheFactory->createDistributed('task_processing::');
@ -738,8 +741,11 @@ class Manager implements IManager {
}
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);
}
@ -775,7 +781,7 @@ class Manager implements IManager {
}
$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;

@ -28,6 +28,7 @@ use OCP\IDBConnection;
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;
@ -478,6 +479,7 @@ class TaskProcessingTest extends \Test\TestCase {
\OC::$server->get(IClientService::class),
\OC::$server->get(IAppManager::class),
\OC::$server->get(ICacheFactory::class),
\OC::$server->get(IFactory::class),
);
}