Skip to content

Commit

Permalink
enh(TaskProcessingService): Cache result of getRegisteredTaskPRocessi…
Browse files Browse the repository at this point in the history
…ngProviders

shaves off some miliseconds

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr authored and backportbot[bot] committed Jan 25, 2025
1 parent 1c6e7d8 commit 88b7a69
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Service/ProvidersAI/TaskProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

class TaskProcessingService {
private ?ICache $cache = null;
private ?array $registeredProviders = null;

public function __construct(
ICacheFactory $cacheFactory,
Expand All @@ -42,14 +43,17 @@ public function __construct(
*/
public function getRegisteredTaskProcessingProviders(): array {
try {
if ($this->registeredProviders !== null) {
return $this->registeredProviders;
}
$cacheKey = '/ex_task_processing_providers';
$records = $this->cache?->get($cacheKey);
if ($records === null) {
$records = $this->mapper->findAllEnabled();
$this->cache?->set($cacheKey, $records);
}

return array_map(static function ($record) {
return $this->registeredProviders = array_map(static function ($record) {
return new TaskProcessingProvider($record);
}, $records);
} catch (Exception) {
Expand Down

0 comments on commit 88b7a69

Please sign in to comment.