From 198cc9d3ac054a8f6e98f6a87c45b87cee494fe7 Mon Sep 17 00:00:00 2001 From: SychO9 Date: Sat, 20 Mar 2021 15:48:42 +0100 Subject: [PATCH 1/2] Eager load ListPostsController needed relations --- src/Api/Controller/ListPostsController.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Api/Controller/ListPostsController.php b/src/Api/Controller/ListPostsController.php index df03b6dfa8..453bd8b94b 100644 --- a/src/Api/Controller/ListPostsController.php +++ b/src/Api/Controller/ListPostsController.php @@ -93,6 +93,14 @@ protected function data(ServerRequestInterface $request, Document $document) $results->areMoreResults() ? null : 0 ); + if (! in_array('discussion', $include)) { + $include[] = 'discussion'; + } + + if (in_array('user', $include)) { + $include[] = 'user.groups'; + } + return $results->getResults()->load($include); } From fd4a5e1371413c3c6294bb7d05406e6e937e51d8 Mon Sep 17 00:00:00 2001 From: SychO9 Date: Sun, 21 Mar 2021 20:00:01 +0100 Subject: [PATCH 2/2] Add comment explaining the reason for eagerloading --- src/Api/Controller/ListPostsController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Api/Controller/ListPostsController.php b/src/Api/Controller/ListPostsController.php index 453bd8b94b..f034838d7f 100644 --- a/src/Api/Controller/ListPostsController.php +++ b/src/Api/Controller/ListPostsController.php @@ -93,6 +93,9 @@ protected function data(ServerRequestInterface $request, Document $document) $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'; }