Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
217 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace App\Jobs\HomeFeedPipeline; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Queue\Middleware\WithoutOverlapping; | ||
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing; | ||
use Illuminate\Support\Facades\Cache; | ||
use App\Follower; | ||
use App\Hashtag; | ||
use App\StatusHashtag; | ||
use App\Services\HashtagFollowService; | ||
use App\Services\StatusService; | ||
use App\Services\HomeTimelineService; | ||
|
||
class HashtagUnfollowPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
protected $pid; | ||
protected $hid; | ||
|
||
public $timeout = 900; | ||
public $tries = 3; | ||
public $maxExceptions = 1; | ||
public $failOnTimeout = true; | ||
|
||
/** | ||
* The number of seconds after which the job's unique lock will be released. | ||
* | ||
* @var int | ||
*/ | ||
public $uniqueFor = 3600; | ||
|
||
/** | ||
* Get the unique ID for the job. | ||
*/ | ||
public function uniqueId(): string | ||
{ | ||
return 'hfp:hashtag:unfollow:' . $this->hid . ':' . $this->pid; | ||
} | ||
|
||
/** | ||
* Get the middleware the job should pass through. | ||
* | ||
* @return array<int, object> | ||
*/ | ||
public function middleware(): array | ||
{ | ||
return [(new WithoutOverlapping("hfp:hashtag:unfollow:{$this->hid}:{$this->pid}"))->shared()->dontRelease()]; | ||
} | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct($hid, $pid) | ||
{ | ||
$this->hid = $hid; | ||
$this->pid = $pid; | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
$hid = $this->hid; | ||
$pid = $this->pid; | ||
|
||
$statusIds = HomeTimelineService::get($pid, 0, -1); | ||
|
||
if(!$statusIds || !count($statusIds)) { | ||
return; | ||
} | ||
|
||
$followingIds = Cache::remember('profile:following:'.$pid, 1209600, function() use($pid) { | ||
$following = Follower::whereProfileId($pid)->pluck('following_id'); | ||
return $following->push($pid)->toArray(); | ||
}); | ||
|
||
foreach($statusIds as $id) { | ||
$status = StatusService::get($id, false); | ||
if(!$status) { | ||
HomeTimelineService::rem($pid, $id); | ||
continue; | ||
} | ||
if(!in_array($status['account']['id'], $followingIds)) { | ||
HomeTimelineService::rem($pid, $id); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace App\Observers; | ||
|
||
use App\HashtagFollow; | ||
use App\Services\HashtagFollowService; | ||
use App\Jobs\HomeFeedPipeline\HashtagUnfollowPipeline; | ||
use Illuminate\Contracts\Events\ShouldHandleEventsAfterCommit; | ||
|
||
class HashtagFollowObserver implements ShouldHandleEventsAfterCommit | ||
{ | ||
/** | ||
* Handle the HashtagFollow "created" event. | ||
*/ | ||
public function created(HashtagFollow $hashtagFollow): void | ||
{ | ||
HashtagFollowService::add($hashtagFollow->hashtag_id, $hashtagFollow->profile_id); | ||
} | ||
|
||
/** | ||
* Handle the HashtagFollow "updated" event. | ||
*/ | ||
public function updated(HashtagFollow $hashtagFollow): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the HashtagFollow "deleting" event. | ||
*/ | ||
public function deleting(HashtagFollow $hashtagFollow): void | ||
{ | ||
HashtagFollowService::unfollow($hashtagFollow->hashtag_id, $hashtagFollow->profile_id); | ||
HashtagUnfollowPipeline::dispatch($hashtagFollow->hashtag_id, $hashtagFollow->profile_id); | ||
} | ||
|
||
/** | ||
* Handle the HashtagFollow "restored" event. | ||
*/ | ||
public function restored(HashtagFollow $hashtagFollow): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the HashtagFollow "force deleted" event. | ||
*/ | ||
public function forceDeleted(HashtagFollow $hashtagFollow): void | ||
{ | ||
HashtagFollowService::unfollow($hashtagFollow->hashtag_id, $hashtagFollow->profile_id); | ||
HashtagUnfollowPipeline::dispatch($hashtagFollow->hashtag_id, $hashtagFollow->profile_id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters