From e84dd3fee34edc3e21bc88bff699b32b0bd31400 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". --- .../core/src/Api/Controller/ShowDiscussionController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index c2bcacc44..cd5aa453e 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/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; }