From e1ddc575dc53056059fe7f0fdf623c7a7144104f Mon Sep 17 00:00:00 2001 From: Edward Hibbert Date: Wed, 15 Jan 2025 16:19:09 +0000 Subject: [PATCH 1/2] WIP speed up /api/v2/networks/N/groups call with includeDetails=true --- app/Group.php | 1 + app/Http/Resources/Group.php | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Group.php b/app/Group.php index 4498211b32..e069c1cad3 100644 --- a/app/Group.php +++ b/app/Group.php @@ -245,6 +245,7 @@ public function getGroupStats($eEmissionRatio = null, $uEmissionratio = null) } $allPastEvents = Party::past() + ->with('allDevices') ->where('events.group', $this->idgroups) ->get(); diff --git a/app/Http/Resources/Group.php b/app/Http/Resources/Group.php index 211a9088fd..49c46cf8fd 100644 --- a/app/Http/Resources/Group.php +++ b/app/Http/Resources/Group.php @@ -274,9 +274,13 @@ class Group extends JsonResource */ public function toArray($request) { - $stats = $this->resource->getGroupStats(); - $stats['events'] = $stats['parties']; - unset($stats['parties']); + $stats = []; + + if ($request->get('includeStats', false)) { + $stats = $this->resource->getGroupStats(); + $stats['events'] = $stats['parties']; + unset($stats['parties']); + } $networkData = gettype($this->network_data) == 'string' ? json_decode($this->network_data, true) : $this->network_data; From 7d25d41c9f39fbc0c64d62036aeb1aee06771c7f Mon Sep 17 00:00:00 2001 From: Edward Hibbert Date: Wed, 15 Jan 2025 17:44:36 +0000 Subject: [PATCH 2/2] WIP speed up /api/v2/networks/N/groups call with includeDetails=true --- app/Http/Controllers/API/NetworkController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Http/Controllers/API/NetworkController.php b/app/Http/Controllers/API/NetworkController.php index 4fc6d8cd90..324013653b 100644 --- a/app/Http/Controllers/API/NetworkController.php +++ b/app/Http/Controllers/API/NetworkController.php @@ -132,6 +132,15 @@ public function getNetworkv2($id) * ) * ), * @OA\Parameter( + * name="includeStats", + * description="Include the stats for each group. This makes the call significantly slower. Default false.", + * required=false, + * in="query", + * @OA\Schema( + * type="boolean" + * ) + * ), + * @OA\Parameter( * name="includeArchived", * description="Include archived groups", * required=false,