diff --git a/CHANGELOG.md b/CHANGELOG.md index c37659fba..6e0d1f104 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,7 @@ - Update AccountImport.vue, fix new IG export format ([59aa6a4b](https://github.com/pixelfed/pixelfed/commit/59aa6a4b)) - Update TransformImports command, fix import service condition ([32c59f04](https://github.com/pixelfed/pixelfed/commit/32c59f04)) - Update AP helpers, more efficently update post count ([7caed381](https://github.com/pixelfed/pixelfed/commit/7caed381)) +- Update AP helpers, refactor post count decrement logic ([b81ae577](https://github.com/pixelfed/pixelfed/commit/b81ae577)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.9 (2023-08-21)](https://github.com/pixelfed/pixelfed/compare/v0.11.8...v0.11.9) diff --git a/app/Jobs/DeletePipeline/DeleteRemoteStatusPipeline.php b/app/Jobs/DeletePipeline/DeleteRemoteStatusPipeline.php index 4969fca2f..77cd5286f 100644 --- a/app/Jobs/DeletePipeline/DeleteRemoteStatusPipeline.php +++ b/app/Jobs/DeletePipeline/DeleteRemoteStatusPipeline.php @@ -22,9 +22,9 @@ use App\Notification; use App\Services\AccountService; use App\Services\NetworkTimelineService; use App\Services\StatusService; -use App\Jobs\ProfilePipeline\DecrementPostCount; use App\Jobs\MediaPipeline\MediaDeletePipeline; use Cache; +use App\Services\Account\AccountStatService; class DeleteRemoteStatusPipeline implements ShouldQueue { @@ -56,10 +56,7 @@ class DeleteRemoteStatusPipeline implements ShouldQueue { $status = $this->status; - if(AccountService::get($status->profile_id, true)) { - DecrementPostCount::dispatch($status->profile_id)->onQueue('low'); - } - + AccountStatService::decrementPostCount($status->profile_id); NetworkTimelineService::del($status->id); StatusService::del($status->id, true); Bookmark::whereStatusId($status->id)->delete(); diff --git a/app/Jobs/ProfilePipeline/DecrementPostCount.php b/app/Jobs/ProfilePipeline/DecrementPostCount.php index b463f1dda..74d0523b5 100644 --- a/app/Jobs/ProfilePipeline/DecrementPostCount.php +++ b/app/Jobs/ProfilePipeline/DecrementPostCount.php @@ -35,18 +35,7 @@ class DecrementPostCount implements ShouldQueue */ public function handle() { - $id = $this->id; - - $profile = Profile::find($id); - - if(!$profile) { - return 1; - } - - $profile->status_count = $profile->status_count ? $profile->status_count - 1 : 0; - $profile->save(); - AccountService::del($id); - - return 1; + // deprecated + return; } } diff --git a/app/Jobs/ProfilePipeline/IncrementPostCount.php b/app/Jobs/ProfilePipeline/IncrementPostCount.php index 1a94f1e6c..a1f9ceca7 100644 --- a/app/Jobs/ProfilePipeline/IncrementPostCount.php +++ b/app/Jobs/ProfilePipeline/IncrementPostCount.php @@ -14,42 +14,12 @@ use App\Profile; use App\Status; use App\Services\AccountService; -class IncrementPostCount implements ShouldQueue, ShouldBeUniqueUntilProcessing +class IncrementPostCount implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; public $id; - 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 'propipe:ipc:' . $this->id; - } - - /** - * Get the middleware the job should pass through. - * - * @return array - */ - public function middleware(): array - { - return [(new WithoutOverlapping("propipe:ipc:{$this->id}"))->shared()->dontRelease()]; - } - /** * Create a new job instance. * @@ -67,20 +37,7 @@ class IncrementPostCount implements ShouldQueue, ShouldBeUniqueUntilProcessing */ public function handle() { - $id = $this->id; - - $profile = Profile::find($id); - - if(!$profile) { - return 1; - } - - $profile->status_count = $profile->status_count + 1; - $profile->last_status_at = now(); - $profile->save(); - AccountService::del($id); - AccountService::get($id); - - return 1; + // deprecated + return; } } diff --git a/app/Jobs/StatusPipeline/RemoteStatusDelete.php b/app/Jobs/StatusPipeline/RemoteStatusDelete.php index 07a2f6236..a81607755 100644 --- a/app/Jobs/StatusPipeline/RemoteStatusDelete.php +++ b/app/Jobs/StatusPipeline/RemoteStatusDelete.php @@ -39,8 +39,8 @@ use App\Services\AccountService; use App\Services\CollectionService; use App\Services\StatusService; use App\Jobs\MediaPipeline\MediaDeletePipeline; -use App\Jobs\ProfilePipeline\DecrementPostCount; use App\Services\NotificationService; +use App\Services\Account\AccountStatService; class RemoteStatusDelete implements ShouldQueue, ShouldBeUniqueUntilProcessing { @@ -109,9 +109,7 @@ class RemoteStatusDelete implements ShouldQueue, ShouldBeUniqueUntilProcessing } StatusService::del($status->id, true); - - DecrementPostCount::dispatch($status->profile_id)->onQueue('inbox'); - + AccountStatService::decrementPostCount($status->profile_id); return $this->unlinkRemoveMedia($status); } diff --git a/app/Services/Account/AccountStatService.php b/app/Services/Account/AccountStatService.php index 0b5d45a3e..12fd3f94f 100644 --- a/app/Services/Account/AccountStatService.php +++ b/app/Services/Account/AccountStatService.php @@ -14,6 +14,11 @@ class AccountStatService return Redis::zadd(self::REFRESH_CACHE_KEY, $pid, $pid); } + public static function decrementPostCount($pid) + { + return Redis::zadd(self::REFRESH_CACHE_KEY, $pid, $pid); + } + public static function removeFromPostCount($pid) { return Redis::zrem(self::REFRESH_CACHE_KEY, $pid); diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index 4e71a2fae..511ef2502 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -39,8 +39,6 @@ use App\Jobs\HomeFeedPipeline\FeedInsertRemotePipeline; use App\Util\Media\License; use App\Models\Poll; use Illuminate\Contracts\Cache\LockTimeoutException; -use App\Jobs\ProfilePipeline\IncrementPostCount; -use App\Jobs\ProfilePipeline\DecrementPostCount; use App\Services\DomainService; use App\Services\UserFilterService; use App\Services\Account\AccountStatService; diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index e26f0a48c..5c9959e17 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -48,8 +48,6 @@ use App\Services\UserFilterService; use App\Services\NetworkTimelineService; use App\Models\Conversation; use App\Models\RemoteReport; -use App\Jobs\ProfilePipeline\IncrementPostCount; -use App\Jobs\ProfilePipeline\DecrementPostCount; use App\Jobs\HomeFeedPipeline\FeedRemoveRemotePipeline; class Inbox