Skip to content

Commit

Permalink
Eager load post.user.groups relation and allow extensions to eager lo…
Browse files Browse the repository at this point in the history
…ad relations (#38)

* Allow extensions to eager load relations
* Eager load post.user.groups
  • Loading branch information
SychO9 authored Apr 7, 2021
1 parent 53465ba commit 7e72ea0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Api/Controller/ListFlagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 7e72ea0

Please sign in to comment.