diff --git a/CHANGELOG.md b/CHANGELOG.md index 505df79bd..c55aaa8a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Added `avatar:storage-deep-clean` command to dispatch remote avatar storage cleanup jobs ([c37b7cde](https://github.com/pixelfed/pixelfed/commit/c37b7cde)) - Added S3 command to rewrite media urls ([5b3a5610](https://github.com/pixelfed/pixelfed/commit/5b3a5610)) - Experimental home feed ([#4752](https://github.com/pixelfed/pixelfed/pull/4752)) ([c39b9afb](https://github.com/pixelfed/pixelfed/commit/c39b9afb)) +- Added `app:hashtag-cached-count-update` command to update cached_count of hashtags and add to scheduler to run every 25 minutes past the hour ([1e31fee6](https://github.com/pixelfed/pixelfed/commit/1e31fee6)) ### Federation - Update Privacy Settings, add support for Mastodon `indexable` search flag ([fc24630e](https://github.com/pixelfed/pixelfed/commit/fc24630e)) diff --git a/app/Console/Commands/HashtagCachedCountUpdate.php b/app/Console/Commands/HashtagCachedCountUpdate.php new file mode 100644 index 000000000..49f354e2b --- /dev/null +++ b/app/Console/Commands/HashtagCachedCountUpdate.php @@ -0,0 +1,57 @@ +option('limit'); + $tags = Hashtag::whereNull('cached_count')->limit($limit)->get(); + $count = count($tags); + if(!$count) { + return; + } + + $bar = $this->output->createProgressBar($count); + $bar->start(); + + foreach($tags as $tag) { + $count = DB::table('status_hashtags')->whereHashtagId($tag->id)->count(); + if(!$count) { + $tag->cached_count = 0; + $tag->saveQuietly(); + $bar->advance(); + continue; + } + $tag->cached_count = $count; + $tag->saveQuietly(); + $bar->advance(); + } + $bar->finish(); + $this->line(' '); + return; + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 7de830c35..4148e38ab 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -44,6 +44,7 @@ class Kernel extends ConsoleKernel $schedule->command('app:import-upload-clean-storage')->twiceDailyAt(1, 13, 32); } $schedule->command('app:notification-epoch-update')->weeklyOn(1, '2:21'); + $schedule->command('app:hashtag-cached-count-update')->hourlyAt(25); } /**