1
0
Fork 0
forked from mirror/pixelfed

Add migration

This commit is contained in:
Daniel Supernault 2022-12-27 03:37:27 -07:00
parent 3d2656bb02
commit d6fbbb45ab
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 36 additions and 8 deletions

View file

@ -3,8 +3,6 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use App\Hashtag;
use App\StatusHashtag;
return new class extends Migration return new class extends Migration
{ {
@ -22,12 +20,6 @@ return new class extends Migration
$table->index('is_nsfw'); $table->index('is_nsfw');
$table->index('is_banned'); $table->index('is_banned');
}); });
foreach(Hashtag::cursor() as $hashtag) {
$count = StatusHashtag::whereHashtagId($hashtag->id)->count();
$hashtag->cached_count = $count;
$hashtag->save();
}
} }
/** /**

View file

@ -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()
{
//
}
};