From 1d67c1a9f12c487b6d07e0f649aaddfe19bd58b6 Mon Sep 17 00:00:00 2001 From: Ian Morland <16573496+imorland@users.noreply.github.com> Date: Mon, 7 Mar 2022 22:27:01 +0000 Subject: [PATCH] Improve whereFlagged subquery (#169) --- src/Database/RecipientsConstraint.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Database/RecipientsConstraint.php b/src/Database/RecipientsConstraint.php index 211a479..d855559 100644 --- a/src/Database/RecipientsConstraint.php +++ b/src/Database/RecipientsConstraint.php @@ -90,8 +90,12 @@ protected function whenFlagged($query) ->whereIn('discussions.id', function ($query) { $query ->select('posts.discussion_id') - ->from('flags') - ->Join('posts', 'flags.post_id', 'posts.id') + ->from('posts') + ->whereIn('posts.id', function ($query) { + $query->select('flags.post_id') + ->from('flags') + ->distinct(); + }) ->distinct(); }); });