From edbcf3ed795d646c187323ae12e300c2631bd42e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 11 Oct 2023 04:42:40 -0600 Subject: [PATCH 1/2] Update RemoteStatusDelete and DecrementPostCount pipelines --- app/Jobs/ProfilePipeline/DecrementPostCount.php | 12 +++--------- app/Jobs/StatusPipeline/RemoteStatusDelete.php | 11 ++++------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/app/Jobs/ProfilePipeline/DecrementPostCount.php b/app/Jobs/ProfilePipeline/DecrementPostCount.php index d6781d7a5..b463f1dda 100644 --- a/app/Jobs/ProfilePipeline/DecrementPostCount.php +++ b/app/Jobs/ProfilePipeline/DecrementPostCount.php @@ -43,15 +43,9 @@ class DecrementPostCount implements ShouldQueue return 1; } - if($profile->updated_at && $profile->updated_at->lt(now()->subDays(30))) { - $profile->status_count = Status::whereProfileId($id)->whereNull(['in_reply_to_id', 'reblog_of_id'])->count(); - $profile->save(); - AccountService::del($id); - } else { - $profile->status_count = $profile->status_count ? $profile->status_count - 1 : 0; - $profile->save(); - AccountService::del($id); - } + $profile->status_count = $profile->status_count ? $profile->status_count - 1 : 0; + $profile->save(); + AccountService::del($id); return 1; } diff --git a/app/Jobs/StatusPipeline/RemoteStatusDelete.php b/app/Jobs/StatusPipeline/RemoteStatusDelete.php index 19c17b54c..c334fd04e 100644 --- a/app/Jobs/StatusPipeline/RemoteStatusDelete.php +++ b/app/Jobs/StatusPipeline/RemoteStatusDelete.php @@ -37,6 +37,7 @@ use App\Services\AccountService; use App\Services\CollectionService; use App\Services\StatusService; use App\Jobs\MediaPipeline\MediaDeletePipeline; +use App\Jobs\ProfilePipeline\DecrementPostCount; class RemoteStatusDelete implements ShouldQueue { @@ -51,7 +52,7 @@ class RemoteStatusDelete implements ShouldQueue */ public $deleteWhenMissingModels = true; - public $timeout = 90; + public $timeout = 180; public $tries = 2; public $maxExceptions = 1; @@ -62,7 +63,7 @@ class RemoteStatusDelete implements ShouldQueue */ public function __construct(Status $status) { - $this->status = $status; + $this->status = $status->withoutRelations(); } /** @@ -77,14 +78,10 @@ class RemoteStatusDelete implements ShouldQueue if($status->deleted_at) { return; } - $profile = $this->status->profile; StatusService::del($status->id, true); - if($profile->status_count && $profile->status_count > 0) { - $profile->status_count = $profile->status_count - 1; - $profile->save(); - } + DecrementPostCount::dispatch($status->profile_id)->onQueue('inbox'); return $this->unlinkRemoveMedia($status); } From f481f3d24819acf8b7c4a3f1b77062a703721944 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 11 Oct 2023 04:56:39 -0600 Subject: [PATCH 2/2] Update RemoteStatusDelete pipeline --- .../StatusPipeline/RemoteStatusDelete.php | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/app/Jobs/StatusPipeline/RemoteStatusDelete.php b/app/Jobs/StatusPipeline/RemoteStatusDelete.php index c334fd04e..5cf0b97b3 100644 --- a/app/Jobs/StatusPipeline/RemoteStatusDelete.php +++ b/app/Jobs/StatusPipeline/RemoteStatusDelete.php @@ -21,6 +21,7 @@ use App\{ }; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; @@ -39,7 +40,7 @@ use App\Services\StatusService; use App\Jobs\MediaPipeline\MediaDeletePipeline; use App\Jobs\ProfilePipeline\DecrementPostCount; -class RemoteStatusDelete implements ShouldQueue +class RemoteStatusDelete implements ShouldQueue, ShouldBeUniqueUntilProcessing { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; @@ -52,9 +53,35 @@ class RemoteStatusDelete implements ShouldQueue */ public $deleteWhenMissingModels = true; + public $tries = 3; + public $maxExceptions = 3; public $timeout = 180; - public $tries = 2; - 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 'status:remote:delete:' . $this->status->id; + } + + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(): array + { + return [(new WithoutOverlapping("status-remote-delete-{$this->status->id}"))->shared()->dontRelease()]; + } /** * Create a new job instance.