Performance: Assign parent discussion to posts so it doesn't have to be reloaded

This commit is contained in:
Toby Zerner 2017-11-11 22:44:45 +10:30
parent b4375e4f7d
commit 99686ef8bb
2 changed files with 20 additions and 2 deletions

View File

@ -93,6 +93,18 @@ class ListDiscussionsController extends AbstractCollectionController
$results->areMoreResults() ? null : 0
);
return $results->getResults();
$results = $results->getResults();
if ($relations = array_intersect($load, ['startPost', 'lastPost'])) {
foreach ($results as $discussion) {
foreach ($relations as $relation) {
if ($discussion->$relation) {
$discussion->$relation->discussion = $discussion;
}
}
}
}
return $results;
}
}

View File

@ -173,6 +173,12 @@ class ShowDiscussionController extends AbstractResourceController
$query->orderBy('time')->skip($offset)->take($limit)->with($include);
return $query->get()->all();
$posts = $query->get()->all();
foreach ($posts as $post) {
$post->discussion = $discussion;
}
return $posts;
}
}