Eager load ListPostsController needed relations (#2717)

* Eager load ListPostsController needed relations
* Add comment explaining the reason for eagerloading
This commit is contained in:
Sami Mazouz 2021-03-22 09:54:18 +01:00 committed by GitHub
parent 8dd57ffed2
commit 3cc18c1da2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -93,6 +93,17 @@ class ListPostsController extends AbstractListController
$results->areMoreResults() ? null : 0 $results->areMoreResults() ? null : 0
); );
// Eager load discussion for use in the policies,
// eager loading does not affect the JSON response,
// the response only includes relations included in the request.
if (! in_array('discussion', $include)) {
$include[] = 'discussion';
}
if (in_array('user', $include)) {
$include[] = 'user.groups';
}
return $results->getResults()->load($include); return $results->getResults()->load($include);
} }