Skip to content

Commit

Permalink
fix(taskrpocessing): Cache result of getAvailableTaskTypes
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr authored and janepie committed Dec 12, 2024
1 parent 565a607 commit b0016d6
Showing 1 changed file with 39 additions and 31 deletions.
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

0 comments on commit b0016d6

Please sign in to comment.