From a28dbccf1acfdc998dcc31fd0efafd09b4476ec2 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sun, 12 Nov 2017 21:14:19 +1030 Subject: [PATCH] Performance: Assign parent discussions to posts so they don't have to be reloaded --- src/Core/Repository/PostRepository.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Core/Repository/PostRepository.php b/src/Core/Repository/PostRepository.php index 7ce6b0906..93f74a7ce 100644 --- a/src/Core/Repository/PostRepository.php +++ b/src/Core/Repository/PostRepository.php @@ -153,7 +153,7 @@ class PostRepository { $discussions = $this->getDiscussionsForPosts($ids, $actor); - return Post::whereIn('id', $ids) + $posts = Post::whereIn('id', $ids) ->where(function ($query) use ($discussions, $actor) { foreach ($discussions as $discussion) { $query->orWhere(function ($query) use ($discussion, $actor) { @@ -165,6 +165,12 @@ class PostRepository $query->orWhereRaw('FALSE'); }); + + foreach ($posts as $post) { + $post->discussion = $discussions->find($post->discussion_id); + } + + return $posts; } /**