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/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, 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;