forked from mirror/pixelfed
Merge pull request #4894 from pixelfed/staging
Update AP helpers, more efficently update post counts
This commit is contained in:
commit
5d89fe8130
5 changed files with 88 additions and 2 deletions
|
@ -93,6 +93,7 @@
|
|||
- Update ApiV1Controller, properly cast boolean sensitive parameter. Fixes #4888 ([0aff126a](https://github.com/pixelfed/pixelfed/commit/0aff126a))
|
||||
- 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))
|
||||
- ([](https://github.com/pixelfed/pixelfed/commit/))
|
||||
|
||||
## [v0.11.9 (2023-08-21)](https://github.com/pixelfed/pixelfed/compare/v0.11.8...v0.11.9)
|
||||
|
|
57
app/Console/Commands/AccountPostCountStatUpdate.php
Normal file
57
app/Console/Commands/AccountPostCountStatUpdate.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\Account\AccountStatService;
|
||||
use App\Status;
|
||||
use App\Profile;
|
||||
|
||||
class AccountPostCountStatUpdate extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:account-post-count-stat-update';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Update post counts from recent activities';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$ids = AccountStatService::getAllPostCountIncr();
|
||||
if(!$ids || !count($ids)) {
|
||||
return;
|
||||
}
|
||||
foreach($ids as $id) {
|
||||
$acct = AccountService::get($id, true);
|
||||
if(!$acct) {
|
||||
AccountStatService::removeFromPostCount($id);
|
||||
continue;
|
||||
}
|
||||
$statusCount = Status::whereProfileId($id)->count();
|
||||
if($statusCount != $acct['statuses_count']) {
|
||||
$profile = Profile::find($id);
|
||||
if(!$profile) {
|
||||
AccountStatService::removeFromPostCount($id);
|
||||
continue;
|
||||
}
|
||||
$profile->status_count = $statusCount;
|
||||
$profile->save();
|
||||
AccountService::del($id);
|
||||
}
|
||||
AccountStatService::removeFromPostCount($id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ class Kernel extends ConsoleKernel
|
|||
}
|
||||
|
||||
if(config('import.instagram.enabled')) {
|
||||
$schedule->command('app:transform-imports')->everyFourMinutes();
|
||||
$schedule->command('app:transform-imports')->everyTenMinutes();
|
||||
$schedule->command('app:import-upload-garbage-collection')->hourlyAt(51);
|
||||
$schedule->command('app:import-remove-deleted-accounts')->hourlyAt(37);
|
||||
$schedule->command('app:import-upload-clean-storage')->twiceDailyAt(1, 13, 32);
|
||||
|
@ -49,6 +49,7 @@ class Kernel extends ConsoleKernel
|
|||
}
|
||||
$schedule->command('app:notification-epoch-update')->weeklyOn(1, '2:21');
|
||||
$schedule->command('app:hashtag-cached-count-update')->hourlyAt(25);
|
||||
$schedule->command('app:account-post-count-stat-update')->everySixHours(25);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
26
app/Services/Account/AccountStatService.php
Normal file
26
app/Services/Account/AccountStatService.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Account;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class AccountStatService
|
||||
{
|
||||
const REFRESH_CACHE_KEY = 'pf:services:accountstats:refresh:daily';
|
||||
|
||||
public static function incrementPostCount($pid)
|
||||
{
|
||||
return Redis::zadd(self::REFRESH_CACHE_KEY, $pid, $pid);
|
||||
}
|
||||
|
||||
public static function removeFromPostCount($pid)
|
||||
{
|
||||
return Redis::zrem(self::REFRESH_CACHE_KEY, $pid);
|
||||
}
|
||||
|
||||
public static function getAllPostCountIncr($limit = -1)
|
||||
{
|
||||
return Redis::zrange(self::REFRESH_CACHE_KEY, 0, $limit);
|
||||
}
|
||||
}
|
|
@ -43,6 +43,7 @@ use App\Jobs\ProfilePipeline\IncrementPostCount;
|
|||
use App\Jobs\ProfilePipeline\DecrementPostCount;
|
||||
use App\Services\DomainService;
|
||||
use App\Services\UserFilterService;
|
||||
use App\Services\Account\AccountStatService;
|
||||
|
||||
class Helpers {
|
||||
|
||||
|
@ -536,7 +537,7 @@ class Helpers {
|
|||
}
|
||||
}
|
||||
|
||||
IncrementPostCount::dispatch($pid)->onQueue('low');
|
||||
AccountStatService::incrementPostCount($pid);
|
||||
|
||||
if( $status->in_reply_to_id === null &&
|
||||
in_array($status->type, ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||
|
|
Loading…
Reference in a new issue