From 448c0610707cad1bcffa2a79a28bf8bb3ded9feb Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 11 Nov 2023 05:43:33 -0700 Subject: [PATCH] Update HomeFeedPipeline, add hashtag jobs --- .../HashtagInsertFanoutPipeline.php | 86 +++++++++++++++++++ .../HashtagRemoveFanoutPipeline.php | 82 ++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 app/Jobs/HomeFeedPipeline/HashtagInsertFanoutPipeline.php create mode 100644 app/Jobs/HomeFeedPipeline/HashtagRemoveFanoutPipeline.php diff --git a/app/Jobs/HomeFeedPipeline/HashtagInsertFanoutPipeline.php b/app/Jobs/HomeFeedPipeline/HashtagInsertFanoutPipeline.php new file mode 100644 index 000000000..64adebadc --- /dev/null +++ b/app/Jobs/HomeFeedPipeline/HashtagInsertFanoutPipeline.php @@ -0,0 +1,86 @@ +hashtag->id; + } + + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(): array + { + return [(new WithoutOverlapping("hfp:hashtag:fanout:insert:{$this->hashtag->id}"))->shared()->dontRelease()]; + } + + /** + * Create a new job instance. + */ + public function __construct(StatusHashtag $hashtag) + { + $this->hashtag = $hashtag; + } + + /** + * Execute the job. + */ + public function handle(): void + { + $hashtag = $this->hashtag; + + $ids = HashtagFollowService::getPidByHid($hashtag->hashtag_id); + + if(!$ids || !count($ids)) { + return; + } + + foreach($ids as $id) { + HomeTimelineService::add($id, $hashtag->status_id); + } + } +} diff --git a/app/Jobs/HomeFeedPipeline/HashtagRemoveFanoutPipeline.php b/app/Jobs/HomeFeedPipeline/HashtagRemoveFanoutPipeline.php new file mode 100644 index 000000000..92e3b8e42 --- /dev/null +++ b/app/Jobs/HomeFeedPipeline/HashtagRemoveFanoutPipeline.php @@ -0,0 +1,82 @@ +hid . ':' . $this->sid; + } + + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(): array + { + return [(new WithoutOverlapping("hfp:hashtag:fanout:remove:{$this->hid}:{$this->sid}"))->shared()->dontRelease()]; + } + + /** + * Create a new job instance. + */ + public function __construct($sid, $hid) + { + $this->sid = $sid; + $this->hid = $hid; + } + + /** + * Execute the job. + */ + public function handle(): void + { + $sid = $this->sid; + $hid = $this->hid; + + $ids = HashtagFollowService::getPidByHid($hid); + + if(!$ids || !count($ids)) { + return; + } + + foreach($ids as $id) { + HomeTimelineService::rem($id, $sid); + } + } +}