mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 09:13:19 -04:00
Merge pull request #55164 from nextcloud/backport/55153/stable31
[stable31] fix(TaskProcessing): Cache task types by user language
This commit is contained in:
commit
92a9b342cf
2 changed files with 12 additions and 2 deletions
|
|
@ -73,6 +73,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;
|
||||
|
||||
|
|
@ -108,6 +110,7 @@ class Manager implements IManager {
|
|||
private IUserManager $userManager,
|
||||
private IUserSession $userSession,
|
||||
ICacheFactory $cacheFactory,
|
||||
private IFactory $l10nFactory,
|
||||
) {
|
||||
$this->appData = $appDataFactory->get('core');
|
||||
$this->distributedCache = $cacheFactory->createDistributed('task_processing::');
|
||||
|
|
@ -813,12 +816,15 @@ class Manager implements IManager {
|
|||
}
|
||||
|
||||
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('available_task_types_v2');
|
||||
$cachedValue = $this->distributedCache->get($cacheKey);
|
||||
if ($cachedValue !== null) {
|
||||
$this->availableTaskTypes = unserialize($cachedValue);
|
||||
}
|
||||
|
|
@ -864,7 +870,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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -28,6 +29,7 @@ use OCP\IServerContainer;
|
|||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\L10N\IFactory;
|
||||
use OCP\TaskProcessing\EShapeType;
|
||||
use OCP\TaskProcessing\Events\GetTaskProcessingProvidersEvent;
|
||||
use OCP\TaskProcessing\Events\TaskFailedEvent;
|
||||
|
|
@ -612,6 +614,7 @@ class TaskProcessingTest extends \Test\TestCase {
|
|||
$userManager,
|
||||
\OC::$server->get(IUserSession::class),
|
||||
\OC::$server->get(ICacheFactory::class),
|
||||
\OC::$server->get(IFactory::class),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -1264,6 +1267,7 @@ class TaskProcessingTest extends \Test\TestCase {
|
|||
\OC::$server->get(IUserManager::class),
|
||||
\OC::$server->get(IUserSession::class),
|
||||
\OC::$server->get(ICacheFactory::class),
|
||||
\OC::$server->get(IFactory::class),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue