Merge pull request #55153 from nextcloud/fix/taskprocessing-task-types-cache-by-language

fix(TaskProcessing): Cache task types by user language
This commit is contained in:
Marcel Klehr 2025-09-18 09:23:27 +02:00 committed by GitHub
commit 613bb766d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View file

@ -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 */
@ -122,6 +122,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::');
@ -835,12 +836,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(self::TASK_TYPES_CACHE_KEY);
$cachedValue = $this->distributedCache->get($cacheKey);
if ($cachedValue !== null) {
$this->availableTaskTypes = unserialize($cachedValue);
}
@ -886,7 +890,7 @@ class Manager implements IManager {
}
$this->availableTaskTypes = $availableTaskTypes;
$this->distributedCache->set(self::TASK_TYPES_CACHE_KEY, serialize($this->availableTaskTypes), 60);
$this->distributedCache->set($cacheKey, serialize($this->availableTaskTypes), 60);
}

View file

@ -32,6 +32,7 @@ use OCP\IServerContainer;
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;
@ -620,6 +621,7 @@ class TaskProcessingTest extends \Test\TestCase {
$userManager,
Server::get(IUserSession::class),
Server::get(ICacheFactory::class),
Server::get(IFactory::class),
);
}
@ -1293,6 +1295,7 @@ class TaskProcessingTest extends \Test\TestCase {
Server::get(IUserManager::class),
Server::get(IUserSession::class),
Server::get(ICacheFactory::class),
Server::get(IFactory::class),
);
}