Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(taskrpocessing): Cache result of getAvailableTaskTypes
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr authored and janepie committed Dec 18, 2024
commit 79023b9f3ec18cf72003822c1e837bc97ae0788a
70 changes: 39 additions & 31 deletions lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -733,41 +733,49 @@ public function getPreferredProvider(string $taskTypeId) {
}

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;
}
Expand Down