Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
enh(TaskProcessingService): Cache result of getRegisteredTaskPRocessi…
…ngProviders

shaves off some miliseconds

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr authored and backportbot[bot] committed Jan 25, 2025
commit b513aab15202231041de6ac223c44a93f632f03e
6 changes: 5 additions & 1 deletion lib/Service/ProvidersAI/TaskProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

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

public function __construct(
ICacheFactory $cacheFactory,
Expand All @@ -47,14 +48,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
Loading