diff options
author | Marcel Klehr <mklehr@gmx.net> | 2024-12-12 11:50:39 +0100 |
---|---|---|
committer | janepie <49834966+janepie@users.noreply.github.com> | 2024-12-18 18:32:34 +0100 |
commit | 79023b9f3ec18cf72003822c1e837bc97ae0788a (patch) | |
tree | 774f8bd7baa2357ecd2d89aa37cc112458263e99 /lib | |
parent | b1d1badcf04867eb0b32dbc9a29f77d4f90d995d (diff) | |
download | nextcloud-server-79023b9f3ec18cf72003822c1e837bc97ae0788a.tar.gz nextcloud-server-79023b9f3ec18cf72003822c1e837bc97ae0788a.zip |
fix(taskrpocessing): Cache result of getAvailableTaskTypes
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/TaskProcessing/Manager.php | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index 2a7bcfab8b8..e263195d35e 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -733,41 +733,49 @@ class Manager implements IManager { } public function getAvailableTaskTypes(bool $showDisabled = false): array { - $taskTypes = $this->_getTaskTypes(); - $taskTypeSettings = $this->_getTaskTypeSettings(); - - $availableTaskTypes = []; - foreach ($taskTypes as $taskType) { - if ((!$showDisabled) && isset($taskTypeSettings[$taskType->getId()]) && !$taskTypeSettings[$taskType->getId()]) { - continue; - } - try { - $provider = $this->getPreferredProvider($taskType->getId()); - } catch (\OCP\TaskProcessing\Exception\Exception $e) { - continue; + // Either we have no cache or showDisabled is turned on, which we don't want to cache, ever. + if ($this->availableTaskTypes === null || $showDisabled) { + $taskTypes = $this->_getTaskTypes(); + $taskTypeSettings = $this->_getTaskTypeSettings(); + + $availableTaskTypes = []; + foreach ($taskTypes as $taskType) { + if ((!$showDisabled) && isset($taskTypeSettings[$taskType->getId()]) && !$taskTypeSettings[$taskType->getId()]) { + continue; + } + try { + $provider = $this->getPreferredProvider($taskType->getId()); + } catch (\OCP\TaskProcessing\Exception\Exception $e) { + continue; + } + try { + $availableTaskTypes[$provider->getTaskTypeId()] = [ + 'name' => $taskType->getName(), + 'description' => $taskType->getDescription(), + 'optionalInputShape' => $provider->getOptionalInputShape(), + 'inputShapeEnumValues' => $provider->getInputShapeEnumValues(), + 'inputShapeDefaults' => $provider->getInputShapeDefaults(), + 'inputShape' => $taskType->getInputShape(), + 'optionalInputShapeEnumValues' => $provider->getOptionalInputShapeEnumValues(), + 'optionalInputShapeDefaults' => $provider->getOptionalInputShapeDefaults(), + 'outputShape' => $taskType->getOutputShape(), + 'outputShapeEnumValues' => $provider->getOutputShapeEnumValues(), + 'optionalOutputShape' => $provider->getOptionalOutputShape(), + 'optionalOutputShapeEnumValues' => $provider->getOptionalOutputShapeEnumValues(), + ]; + } catch (\Throwable $e) { + $this->logger->error('Failed to set up TaskProcessing provider ' . $provider::class, ['exception' => $e]); + } } - try { - $availableTaskTypes[$provider->getTaskTypeId()] = [ - 'name' => $taskType->getName(), - 'description' => $taskType->getDescription(), - 'optionalInputShape' => $provider->getOptionalInputShape(), - 'inputShapeEnumValues' => $provider->getInputShapeEnumValues(), - 'inputShapeDefaults' => $provider->getInputShapeDefaults(), - 'inputShape' => $taskType->getInputShape(), - 'optionalInputShapeEnumValues' => $provider->getOptionalInputShapeEnumValues(), - 'optionalInputShapeDefaults' => $provider->getOptionalInputShapeDefaults(), - 'outputShape' => $taskType->getOutputShape(), - 'outputShapeEnumValues' => $provider->getOutputShapeEnumValues(), - 'optionalOutputShape' => $provider->getOptionalOutputShape(), - 'optionalOutputShapeEnumValues' => $provider->getOptionalOutputShapeEnumValues(), - ]; - } catch (\Throwable $e) { - $this->logger->error('Failed to set up TaskProcessing provider ' . $provider::class, ['exception' => $e]); + + if ($showDisabled) { + // Do not cache showDisabled, ever. + return $availableTaskTypes; } + + $this->availableTaskTypes = $availableTaskTypes; } - $this->availableTaskTypes = $availableTaskTypes; - return $this->availableTaskTypes; } |