mirror of
https://github.com/flarum/framework.git
synced 2024-11-30 13:36:10 +08:00
Performance: Assign parent discussion to posts so it doesn't have to be reloaded
This commit is contained in:
parent
b4375e4f7d
commit
99686ef8bb
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user