Skip to content

Commit ea6d88b

Browse files
marcelklehrbackportbot[bot]
authored andcommitted
fix(TaskProcessing): Cache providersById in getPreferredProviders
Signed-off-by: Marcel Klehr <mklehr@gmx.net> [skip ci]
1 parent e41a95c commit ea6d88b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/private/TaskProcessing/Manager.php

+8-3
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

@@ -717,9 +718,13 @@ public function getPreferredProvider(string $taskTypeId) {
717718

718719
$providers = $this->getProviders();
719720
if (isset($this->preferences[$taskTypeId])) {
720-
$provider = current(array_values(array_filter($providers, fn ($provider) => $provider->getId() === $this->preferences[$taskTypeId])));
721-
if ($provider !== false) {
722-
return $provider;
721+
$providersById = $this->providersById ?? array_reduce($providers, static function (array $carry, IProvider $provider) {
722+
$carry[$provider->getId()] = $provider;
723+
return $carry;
724+
}, []);
725+
$this->providersById = $providersById;
726+
if (isset($providersById[$this->preferences[$taskTypeId]])) {
727+
return $providersById[$this->preferences[$taskTypeId]];
723728
}
724729
}
725730
// By default, use the first available provider

0 commit comments

Comments
 (0)