mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-09 16:24:51 +00:00
commit
fcbd225542
2 changed files with 77 additions and 0 deletions
75
app/Console/Commands/FixLikes.php
Normal file
75
app/Console/Commands/FixLikes.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\{Like, Status};
|
||||
use DB;
|
||||
|
||||
class FixLikes extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'fix:likes';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fix Like counts';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$chunk = 100;
|
||||
$limit = Like::groupBy('status_id')->get()->count();
|
||||
|
||||
if($limit > 1000) {
|
||||
if($this->confirm('We have found more than 1000 records to update, this may take a few moments. Are you sure you want to continue?') == false) {
|
||||
$this->error('Cancelling command...');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$bar = $this->output->createProgressBar($limit);
|
||||
$this->line(' ');
|
||||
$this->info(' Starting like count fix ...');
|
||||
$this->line(' ');
|
||||
$bar->start();
|
||||
|
||||
Like::selectRaw('count(id) as count, status_id')
|
||||
->groupBy('status_id')
|
||||
->chunk($chunk, function($likes) use($bar) {
|
||||
foreach($likes as $like) {
|
||||
$s = Status::find($like['status_id']);
|
||||
if($s && $s->likes_count == 0) {
|
||||
$s->likes_count = $like['count'];
|
||||
$s->save();
|
||||
}
|
||||
$bar->advance();
|
||||
}
|
||||
});
|
||||
|
||||
$bar->finish();
|
||||
$this->line(' ');
|
||||
$this->line(' ');
|
||||
}
|
||||
}
|
|
@ -646,6 +646,8 @@ class PublicApiController extends Controller
|
|||
'in_reply_to_id',
|
||||
'reblog_of_id',
|
||||
'is_nsfw',
|
||||
'likes_count',
|
||||
'reblogs_count',
|
||||
'scope',
|
||||
'local',
|
||||
'created_at',
|
||||
|
|
Loading…
Reference in a new issue