mirror of
https://github.com/flarum/framework.git
synced 2024-11-26 10:14:16 +08:00
Performance: Assign parent discussion to posts so it doesn't have to be reloaded
This commit is contained in:
parent
1a102766a9
commit
5f7060fb4a
|
@ -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