Skip to content

Commit

Permalink
Merge pull request #697 from pinkary-project/feat/following-feed-speed
Browse files Browse the repository at this point in the history
feat: following-feed-speed
  • Loading branch information
nunomaduro authored Oct 11, 2024
2 parents 3026219 + 7c4beb1 commit 32d8e7d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/Queries/Feeds/QuestionsFollowingFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Question;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Facades\DB;

final readonly class QuestionsFollowingFeed
Expand All @@ -27,7 +28,12 @@ public function builder(): Builder
{
$followQueryClosure = function (Builder $query): void {
$query->where('to_id', $this->user->id)
->orWhereIn('to_id', DB::table('followers')->select('user_id')->where('follower_id', $this->user->id));
->orWhereExists(function (Builder|QueryBuilder $query): void {
$query->select(DB::raw(1))
->from('followers')
->whereColumn('user_id', 'to_id')
->where('follower_id', $this->user->id);
});
};

return Question::query()
Expand Down

0 comments on commit 32d8e7d

Please sign in to comment.