fix(taskprocessing): cache provider settings in distributed cache as well

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
pull/50331/head
Marcel Klehr 12 months ago
parent 6f94ddc1d5
commit c489d7d8a5
  1. 12
      lib/private/TaskProcessing/Manager.php

@ -81,6 +81,7 @@ class Manager implements IManager {
private IAppData $appData;
private ?array $preferences = null;
private ICache $cache;
private ICache $distributedCache;
public function __construct(
private IConfig $config,
@ -100,6 +101,7 @@ class Manager implements IManager {
) {
$this->appData = $appDataFactory->get('core');
$this->cache = $cacheFactory->createLocal('task_processing::');
$this->cache = $cacheFactory->createDistributed('task_processing::');
}
@ -732,7 +734,14 @@ class Manager implements IManager {
public function getPreferredProvider(string $taskTypeId) {
try {
$this->preferences = $this->preferences ?? json_decode($this->config->getAppValue('core', 'ai.taskprocessing_provider_preferences', 'null'), associative: true, flags: JSON_THROW_ON_ERROR);
if ($this->preferences === null) {
$this->preferences = $this->distributedCache->get('ai.taskprocessing_provider_preferences');
if ($this->preferences === null) {
$this->preferences = json_decode($this->config->getAppValue('core', 'ai.taskprocessing_provider_preferences', 'null'), associative: true, flags: JSON_THROW_ON_ERROR);
$this->distributedCache->set('ai.taskprocessing_provider_preferences', $this->preferences, 60 * 3);
}
}
$providers = $this->getProviders();
if (isset($this->preferences[$taskTypeId])) {
$provider = current(array_values(array_filter($providers, fn ($provider) => $provider->getId() === $this->preferences[$taskTypeId])));
@ -754,6 +763,7 @@ class Manager implements IManager {
public function getAvailableTaskTypes(bool $showDisabled = false): array {
if ($this->availableTaskTypes === null) {
// We use local cache only because distributed cache uses JSOn stringify which would botch our ShapeDescriptor objects
$this->availableTaskTypes = $this->cache->get('available_task_types');
}
// Either we have no cache or showDisabled is turned on, which we don't want to cache, ever.

Loading…
Cancel
Save