From 7e72ea04007f84fe8c651762bd7335a88046ed71 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Wed, 7 Apr 2021 16:24:52 +0100 Subject: [PATCH] Eager load post.user.groups relation and allow extensions to eager load relations (#38) * Allow extensions to eager load relations * Eager load post.user.groups --- src/Api/Controller/ListFlagsController.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Api/Controller/ListFlagsController.php b/src/Api/Controller/ListFlagsController.php index e9ade26..cf89dd0 100644 --- a/src/Api/Controller/ListFlagsController.php +++ b/src/Api/Controller/ListFlagsController.php @@ -38,16 +38,24 @@ class ListFlagsController extends AbstractListController protected function data(ServerRequestInterface $request, Document $document) { $actor = $request->getAttribute('actor'); + $include = $this->extractInclude($request); $actor->assertRegistered(); $actor->read_flags_at = time(); $actor->save(); - return Flag::whereVisibleTo($actor) - ->with($this->extractInclude($request)) + $flags = Flag::whereVisibleTo($actor) ->latest('flags.created_at') ->groupBy('post_id') ->get(); + + if (in_array('post.user', $include)) { + $include[] = 'post.user.groups'; + } + + $this->loadRelations($flags, $include); + + return $flags; } }