From 6dcd472be67e49187edc7035ceb8d1ff8d64d3b0 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 27 Dec 2020 14:45:31 -0700 Subject: [PATCH 1/2] Update Profile, fix status count --- app/Console/Commands/FixStatusCount.php | 56 +++++++++++++++++++ app/Http/Controllers/StatusController.php | 1 + app/Jobs/StatusPipeline/StatusDelete.php | 11 ++++ app/Jobs/StatusPipeline/StatusEntityLexer.php | 11 ++++ app/Profile.php | 16 +----- 5 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 app/Console/Commands/FixStatusCount.php diff --git a/app/Console/Commands/FixStatusCount.php b/app/Console/Commands/FixStatusCount.php new file mode 100644 index 00000000..218526b1 --- /dev/null +++ b/app/Console/Commands/FixStatusCount.php @@ -0,0 +1,56 @@ +chunk(50, function($profiles) { + foreach($profiles as $profile) { + $profile->status_count = $profile->statuses() + ->getQuery() + ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) + ->whereNull('in_reply_to_id') + ->whereNull('reblog_of_id') + ->count(); + $profile->save(); + } + }); + + return 0; + } +} diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index c2e573ea..34aa16c4 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -210,6 +210,7 @@ class StatusController extends Controller } Cache::forget('_api:statuses:recent_9:' . $status->profile_id); + Cache::forget('profile:status_count:' . $status->profile_id); if ($status->profile_id == $user->profile->id || $user->is_admin == true) { Cache::forget('profile:status_count:'.$status->profile_id); StatusDelete::dispatch($status); diff --git a/app/Jobs/StatusPipeline/StatusDelete.php b/app/Jobs/StatusPipeline/StatusDelete.php index 346f1cf6..ede5c67e 100644 --- a/app/Jobs/StatusPipeline/StatusDelete.php +++ b/app/Jobs/StatusPipeline/StatusDelete.php @@ -56,6 +56,17 @@ class StatusDelete implements ShouldQueue public function handle() { $status = $this->status; + $profile = $this->status->profile; + + $count = $profile->statuses() + ->getQuery() + ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) + ->whereNull('in_reply_to_id') + ->whereNull('reblog_of_id') + ->count(); + + $profile->status_count = ($count - 1); + $profile->save(); if(config('federation.activitypub.enabled') == true) { $this->fanoutDelete($status); diff --git a/app/Jobs/StatusPipeline/StatusEntityLexer.php b/app/Jobs/StatusPipeline/StatusEntityLexer.php index ce04c687..e173c639 100644 --- a/app/Jobs/StatusPipeline/StatusEntityLexer.php +++ b/app/Jobs/StatusPipeline/StatusEntityLexer.php @@ -52,6 +52,17 @@ class StatusEntityLexer implements ShouldQueue public function handle() { $profile = $this->status->profile; + + $count = $profile->statuses() + ->getQuery() + ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) + ->whereNull('in_reply_to_id') + ->whereNull('reblog_of_id') + ->count(); + + $profile->status_count = $count; + $profile->save(); + if($profile->no_autolink == false) { $this->parseEntities(); } diff --git a/app/Profile.php b/app/Profile.php index c88b876f..c4d07b84 100644 --- a/app/Profile.php +++ b/app/Profile.php @@ -91,21 +91,7 @@ class Profile extends Model public function statusCount() { - return Cache::remember('profile:status_count:'.$this->id, now()->addMonths(1), function() { - $count = $this->status_count; - if($count) { - return $count; - } - $count = $this->statuses() - ->getQuery() - ->whereHas('media') - ->whereNull('in_reply_to_id') - ->whereNull('reblog_of_id') - ->count(); - $this->status_count = $count; - $this->save(); - return $count; - }); + return $this->status_count; } public function following() From 8e85728994706bec8e95ad1ee48ea3e7b671c031 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 27 Dec 2020 14:46:08 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6999471..2f85cf8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -146,6 +146,8 @@ - Updated antispam bouncer, change recent from 1 week to 3 months. ([7d818197](https://github.com/pixelfed/pixelfed/commit/7d818197)) - Updated Post components, fix remote post and profile urls. ([cfcf17f3](https://github.com/pixelfed/pixelfed/commit/cfcf17f3)) - Update migrations, fix broken oauth change. ([4a885c88](https://github.com/pixelfed/pixelfed/commit/4a885c88)) +- Update LikeController, store status_profile_id and is_comment attributes. ([799a4cba](https://github.com/pixelfed/pixelfed/commit/799a4cba)) +- Updated Profile, fix status count. ([6dcd472b](https://github.com/pixelfed/pixelfed/commit/6dcd472b)) ## [v0.10.9 (2020-04-17)](https://github.com/pixelfed/pixelfed/compare/v0.10.8...v0.10.9) ### Added