mirror of
https://github.com/flarum/core.git
synced 2025-08-15 04:44:08 +02:00
Eager load more necessary related mentions (#72)
* perf: Eager load related mentions from the extender These missing relations caused more queries to be called, the more mentions posts have the more queries produced. * perf: Eager load models in show endpoints Can't use the extender for that
This commit is contained in:
@@ -44,6 +44,8 @@ class FilterVisiblePosts
|
||||
*/
|
||||
public function __invoke(Controller\AbstractSerializeController $controller, $data, ServerRequestInterface $request)
|
||||
{
|
||||
$relations = [];
|
||||
|
||||
// Firstly we gather a list of posts contained within the API document.
|
||||
// This will vary according to the API endpoint that is being accessed.
|
||||
if ($controller instanceof Controller\ShowDiscussionController) {
|
||||
@@ -51,6 +53,11 @@ class FilterVisiblePosts
|
||||
} elseif ($controller instanceof Controller\ShowPostController
|
||||
|| $controller instanceof Controller\CreatePostController
|
||||
|| $controller instanceof Controller\UpdatePostController) {
|
||||
$relations = [
|
||||
'mentionsUsers', 'mentionsPosts', 'mentionsPosts.user', 'mentionedBy',
|
||||
'mentionedBy.mentionsPosts', 'mentionedBy.mentionsPosts.user', 'mentionedBy.mentionsUsers'
|
||||
];
|
||||
|
||||
$posts = [$data];
|
||||
} elseif ($controller instanceof Controller\ListPostsController) {
|
||||
$posts = $data;
|
||||
@@ -67,7 +74,7 @@ class FilterVisiblePosts
|
||||
// Load all of the users that these posts mention. This way the data
|
||||
// will be ready to go when we need to sub in current usernames
|
||||
// during the rendering process.
|
||||
$posts->loadMissing(['mentionsUsers', 'mentionsPosts.user', 'mentionedBy']);
|
||||
$posts->loadMissing($relations);
|
||||
|
||||
// Construct a list of the IDs of all of the posts that these posts
|
||||
// have been mentioned in. We can then filter this list of IDs to
|
||||
|
Reference in New Issue
Block a user