From 8548294c7a2396ec531867fcdd6ffb814508faee Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 3 Dec 2023 03:06:32 -0700 Subject: [PATCH] Update HomeFeedPipeline, observe mutes/blocks during fanout --- .../HomeFeedPipeline/FeedFollowPipeline.php | 2 +- .../HomeFeedPipeline/FeedInsertPipeline.php | 27 +++++++++++++++++-- .../FeedInsertRemotePipeline.php | 23 +++++++++++++++- .../HashtagInsertFanoutPipeline.php | 7 ++++- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/app/Jobs/HomeFeedPipeline/FeedFollowPipeline.php b/app/Jobs/HomeFeedPipeline/FeedFollowPipeline.php index 64d646354..e386329ca 100644 --- a/app/Jobs/HomeFeedPipeline/FeedFollowPipeline.php +++ b/app/Jobs/HomeFeedPipeline/FeedFollowPipeline.php @@ -69,7 +69,7 @@ class FeedFollowPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing $actorId = $this->actorId; $followingId = $this->followingId; - $minId = SnowflakeService::byDate(now()->subMonths(6)); + $minId = SnowflakeService::byDate(now()->subWeeks(6)); $ids = Status::where('id', '>', $minId) ->where('profile_id', $followingId) diff --git a/app/Jobs/HomeFeedPipeline/FeedInsertPipeline.php b/app/Jobs/HomeFeedPipeline/FeedInsertPipeline.php index bf9c849a5..2456d2aa7 100644 --- a/app/Jobs/HomeFeedPipeline/FeedInsertPipeline.php +++ b/app/Jobs/HomeFeedPipeline/FeedInsertPipeline.php @@ -10,8 +10,10 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing; +use App\UserFilter; use App\Services\FollowerService; use App\Services\HomeTimelineService; +use App\Services\StatusService; class FeedInsertPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing { @@ -64,11 +66,32 @@ class FeedInsertPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing */ public function handle(): void { - $ids = FollowerService::localFollowerIds($this->pid); + $sid = $this->sid; + $status = StatusService::get($sid, false); + + if(!$status) { + return; + } + + if(!in_array($status['pf_type'], ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])) { + return; + } HomeTimelineService::add($this->pid, $this->sid); + + + $ids = FollowerService::localFollowerIds($this->pid); + + if(!$ids || !count($ids)) { + return; + } + + $skipIds = UserFilter::whereFilterableType('App\Profile')->whereFilterableId($status['account']['id'])->whereIn('filter_type', ['mute', 'block'])->pluck('user_id')->toArray(); + foreach($ids as $id) { - HomeTimelineService::add($id, $this->sid); + if(!in_array($id, $skipIds)) { + HomeTimelineService::add($id, $this->sid); + } } } } diff --git a/app/Jobs/HomeFeedPipeline/FeedInsertRemotePipeline.php b/app/Jobs/HomeFeedPipeline/FeedInsertRemotePipeline.php index 579c290a7..738c09699 100644 --- a/app/Jobs/HomeFeedPipeline/FeedInsertRemotePipeline.php +++ b/app/Jobs/HomeFeedPipeline/FeedInsertRemotePipeline.php @@ -10,8 +10,10 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing; +use App\UserFilter; use App\Services\FollowerService; use App\Services\HomeTimelineService; +use App\Services\StatusService; class FeedInsertRemotePipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing { @@ -64,10 +66,29 @@ class FeedInsertRemotePipeline implements ShouldQueue, ShouldBeUniqueUntilProces */ public function handle(): void { + $sid = $this->sid; + $status = StatusService::get($sid, false); + + if(!$status) { + return; + } + + if(!in_array($status['pf_type'], ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])) { + return; + } + $ids = FollowerService::localFollowerIds($this->pid); + if(!$ids || !count($ids)) { + return; + } + + $skipIds = UserFilter::whereFilterableType('App\Profile')->whereFilterableId($status['account']['id'])->whereIn('filter_type', ['mute', 'block'])->pluck('user_id')->toArray(); + foreach($ids as $id) { - HomeTimelineService::add($id, $this->sid); + if(!in_array($id, $skipIds)) { + HomeTimelineService::add($id, $this->sid); + } } } } diff --git a/app/Jobs/HomeFeedPipeline/HashtagInsertFanoutPipeline.php b/app/Jobs/HomeFeedPipeline/HashtagInsertFanoutPipeline.php index 581b8784f..2e6bf4758 100644 --- a/app/Jobs/HomeFeedPipeline/HashtagInsertFanoutPipeline.php +++ b/app/Jobs/HomeFeedPipeline/HashtagInsertFanoutPipeline.php @@ -10,6 +10,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use App\Hashtag; use App\StatusHashtag; +use App\UserFilter; use App\Services\HashtagFollowService; use App\Services\HomeTimelineService; use App\Services\StatusService; @@ -84,6 +85,8 @@ class HashtagInsertFanoutPipeline implements ShouldQueue, ShouldBeUniqueUntilPro return; } + $skipIds = UserFilter::whereFilterableType('App\Profile')->whereFilterableId($status['account']['id'])->whereIn('filter_type', ['mute', 'block'])->pluck('user_id')->toArray(); + $ids = HashtagFollowService::getPidByHid($hashtag->hashtag_id); if(!$ids || !count($ids)) { @@ -91,7 +94,9 @@ class HashtagInsertFanoutPipeline implements ShouldQueue, ShouldBeUniqueUntilPro } foreach($ids as $id) { - HomeTimelineService::add($id, $hashtag->status_id); + if(!in_array($id, $skipIds)) { + HomeTimelineService::add($id, $hashtag->status_id); + } } } }