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".
This commit is contained in:
Toby Zerner 2016-11-28 11:18:27 +10:30
parent aeb0a411b9
commit dd209b1747

View File

@ -83,6 +83,10 @@ class ShowDiscussionController extends AbstractResourceController
$this->includePosts($discussion, $request, $postRelationships); $this->includePosts($discussion, $request, $postRelationships);
} }
$discussion->load(array_filter($include, function ($relationship) {
return ! starts_with($relationship, 'posts');
}));
return $discussion; return $discussion;
} }