forked from mirror/pixelfed
Add migration
This commit is contained in:
parent
3d2656bb02
commit
d6fbbb45ab
2 changed files with 36 additions and 8 deletions
|
@ -3,8 +3,6 @@
|
|||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use App\Hashtag;
|
||||
use App\StatusHashtag;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
|
@ -22,12 +20,6 @@ return new class extends Migration
|
|||
$table->index('is_nsfw');
|
||||
$table->index('is_banned');
|
||||
});
|
||||
|
||||
foreach(Hashtag::cursor() as $hashtag) {
|
||||
$count = StatusHashtag::whereHashtagId($hashtag->id)->count();
|
||||
$hashtag->cached_count = $count;
|
||||
$hashtag->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Hashtag;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Hashtag::chunkById(100, function($hashtags) {
|
||||
foreach($hashtags as $hashtag) {
|
||||
$count = DB::table('status_hashtags')->whereHashtagId($hashtag->id)->count();
|
||||
$hashtag->cached_count = $count;
|
||||
$hashtag->save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue