Skip to content

Commit

Permalink
fix(taskprocessing): cache provider settings in distributed cache as …
Browse files Browse the repository at this point in the history
…well

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Jan 23, 2025
1 parent 5b78276 commit 3d1f189
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -100,6 +101,7 @@ public function __construct(
) {
$this->appData = $appDataFactory->get('core');
$this->cache = $cacheFactory->createLocal('task_processing::');
$this->cache = $cacheFactory->createDistributed('task_processing::');
}


Expand Down Expand Up @@ -732,7 +734,14 @@ public function getProviders(): array {

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])));
Expand All @@ -754,6 +763,7 @@ public function getPreferredProvider(string $taskTypeId) {

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.
Expand Down

0 comments on commit 3d1f189

Please sign in to comment.