From dd209b174703bf065d77d2abba8797943be60cc6 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 28 Nov 2016 11:18:27 +1030 Subject: [PATCH] Eager load discussion relationships Since extensions may add nested includes, we need to make sure they are eager-loaded to avoid excessive queries. For example, when the tags extension adds "tags" and "tags.state". --- src/Api/Controller/ShowDiscussionController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Api/Controller/ShowDiscussionController.php b/src/Api/Controller/ShowDiscussionController.php index c2bcacc44..cd5aa453e 100644 --- a/src/Api/Controller/ShowDiscussionController.php +++ b/src/Api/Controller/ShowDiscussionController.php @@ -83,6 +83,10 @@ class ShowDiscussionController extends AbstractResourceController $this->includePosts($discussion, $request, $postRelationships); } + $discussion->load(array_filter($include, function ($relationship) { + return ! starts_with($relationship, 'posts'); + })); + return $discussion; }