Optimize queries for statistics.

This commit is contained in:
James Cole
2025-09-26 06:05:37 +02:00
parent 08879d31ba
commit 4ec2fcdb8a
92 changed files with 6499 additions and 6514 deletions

View File

@@ -43,16 +43,15 @@ use stdClass;
class WebhookEnrichment implements EnrichmentInterface
{
private Collection $collection;
private User $user; // @phpstan-ignore-line
private UserGroup $userGroup; // @phpstan-ignore-line
private array $ids = [];
private array $deliveries = [];
private array $responses = [];
private array $triggers = [];
private array $webhookDeliveries = [];
private array $webhookResponses = [];
private array $webhookTriggers = [];
private array $deliveries = []; // @phpstan-ignore-line
private array $ids = []; // @phpstan-ignore-line
private array $responses = [];
private array $triggers = [];
private User $user;
private UserGroup $userGroup;
private array $webhookDeliveries = [];
private array $webhookResponses = [];
private array $webhookTriggers = [];
public function enrich(Collection $collection): Collection
{
@@ -67,7 +66,7 @@ class WebhookEnrichment implements EnrichmentInterface
return $this->collection;
}
public function enrichSingle(array|Model $model): array|Model
public function enrichSingle(array | Model $model): array | Model
{
Log::debug(__METHOD__);
$collection = new Collection()->push($model);
@@ -86,6 +85,20 @@ class WebhookEnrichment implements EnrichmentInterface
$this->userGroup = $userGroup;
}
private function appendCollectedInfo(): void
{
$this->collection = $this->collection->map(function (Webhook $item) {
$meta = [
'deliveries' => $this->webhookDeliveries[$item->id] ?? [],
'responses' => $this->webhookResponses[$item->id] ?? [],
'triggers' => $this->webhookTriggers[$item->id] ?? [],
];
$item->meta = $meta;
return $item;
});
}
private function collectIds(): void
{
/** @var Webhook $webhook */
@@ -147,18 +160,4 @@ class WebhookEnrichment implements EnrichmentInterface
$this->webhookTriggers[$id][] = WebhookTriggerEnum::from($this->triggers[$triggerId])->name;
}
}
private function appendCollectedInfo(): void
{
$this->collection = $this->collection->map(function (Webhook $item) {
$meta = [
'deliveries' => $this->webhookDeliveries[$item->id] ?? [],
'responses' => $this->webhookResponses[$item->id] ?? [],
'triggers' => $this->webhookTriggers[$item->id] ?? [],
];
$item->meta = $meta;
return $item;
});
}
}