From 43443503a1e0e37419a6143284a3ae57fd3d7a4a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 12 Nov 2023 23:00:33 -0700 Subject: [PATCH] Update FeedFollowPipeline, use more efficient query --- app/Jobs/HomeFeedPipeline/FeedFollowPipeline.php | 6 +++++- app/Services/HomeTimelineService.php | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Jobs/HomeFeedPipeline/FeedFollowPipeline.php b/app/Jobs/HomeFeedPipeline/FeedFollowPipeline.php index 841409b6f..64d646354 100644 --- a/app/Jobs/HomeFeedPipeline/FeedFollowPipeline.php +++ b/app/Jobs/HomeFeedPipeline/FeedFollowPipeline.php @@ -12,6 +12,7 @@ use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing; use App\Services\AccountService; use App\Services\HomeTimelineService; +use App\Services\SnowflakeService; use App\Status; class FeedFollowPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing @@ -68,7 +69,10 @@ class FeedFollowPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing $actorId = $this->actorId; $followingId = $this->followingId; - $ids = Status::where('profile_id', $followingId) + $minId = SnowflakeService::byDate(now()->subMonths(6)); + + $ids = Status::where('id', '>', $minId) + ->where('profile_id', $followingId) ->whereNull(['in_reply_to_id', 'reblog_of_id']) ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) ->whereIn('visibility',['public', 'unlisted', 'private']) diff --git a/app/Services/HomeTimelineService.php b/app/Services/HomeTimelineService.php index 35d9f405f..075791362 100644 --- a/app/Services/HomeTimelineService.php +++ b/app/Services/HomeTimelineService.php @@ -73,7 +73,10 @@ class HomeTimelineService return $following->push($id)->toArray(); }); - $ids = Status::whereIn('profile_id', $following) + $minId = SnowflakeService::byDate(now()->subMonths(6)); + + $ids = Status::where('id', '>', $minId) + ->whereIn('profile_id', $following) ->whereNull(['in_reply_to_id', 'reblog_of_id']) ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) ->whereIn('visibility',['public', 'unlisted', 'private'])