Skip to content

Commit a610002

Browse files
committed
fix(TaskProcessing): Cache providersById in getPreferredProviders
Signed-off-by: Marcel Klehr <[email protected]>
1 parent c1db2eb commit a610002

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/private/TaskProcessing/Manager.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Manager implements IManager {
8080

8181
private IAppData $appData;
8282
private ?array $preferences = null;
83+
private ?array $providersById = null;
8384
private ICache $cache;
8485
private ICache $distributedCache;
8586

@@ -744,9 +745,13 @@ public function getPreferredProvider(string $taskTypeId) {
744745

745746
$providers = $this->getProviders();
746747
if (isset($this->preferences[$taskTypeId])) {
747-
$provider = current(array_values(array_filter($providers, fn ($provider) => $provider->getId() === $this->preferences[$taskTypeId])));
748-
if ($provider !== false) {
749-
return $provider;
748+
$providersById = $this->providersById ?? array_reduce($providers, static function (array $carry, IProvider $provider) {
749+
$carry[$provider->getId()] = $provider;
750+
return $carry;
751+
}, []);
752+
$this->providersById = $providersById;
753+
if (isset($providersById[$this->preferences[$taskTypeId]])) {
754+
return $providersById[$this->preferences[$taskTypeId]];
750755
}
751756
}
752757
// By default, use the first available provider

0 commit comments

Comments
 (0)