Skip to content

Commit

Permalink
enh(TaskProcessing): Cache providersById in getPreferredProviders
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Jan 24, 2025
1 parent 25e6a78 commit 028e6e2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Manager implements IManager {

private IAppData $appData;
private ?array $preferences = null;
private ?array $providersById = null;
private ICache $cache;
private ICache $distributedCache;

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

$providers = $this->getProviders();
if (isset($this->preferences[$taskTypeId])) {
$provider = current(array_values(array_filter($providers, fn ($provider) => $provider->getId() === $this->preferences[$taskTypeId])));
if ($provider !== false) {
return $provider;
$providersById = $this->providersById ?? array_reduce($providers, static function (array $carry, IProvider $provider) {
$carry[$provider->getId()] = $provider;
return $carry;
}, []);
$this->providersById = $providersById;
if (isset($providersById[$this->preferences[$taskTypeId]])) {
return $providersById[$this->preferences[$taskTypeId]];
}
}
// By default, use the first available provider
Expand Down

0 comments on commit 028e6e2

Please sign in to comment.