X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FConsole%2FCommands%2FChatlibDatabase.php;h=9bf143f11e9956d188f81c4e241ba6a749e57876;hb=HEAD;hp=b95bb64a06a6dbec47b333c2c9248493e0c8492d;hpb=a45648fa8ecf7712c7fd00eb2b93e862b5264f04;p=alttp.git diff --git a/app/Console/Commands/ChatlibDatabase.php b/app/Console/Commands/ChatlibDatabase.php index b95bb64..9bf143f 100644 --- a/app/Console/Commands/ChatlibDatabase.php +++ b/app/Console/Commands/ChatlibDatabase.php @@ -13,14 +13,14 @@ class ChatlibDatabase extends Command { * * @var string */ - protected $signature = 'chatlib:database'; + protected $signature = 'chatlib:database {which=de} {size=3}'; /** * The console command description. * * @var string */ - protected $description = 'Updates the ChatLib database'; + protected $description = 'Update a ChatLib database'; /** * Execute the console command. @@ -28,31 +28,41 @@ class ChatlibDatabase extends Command { * @return int */ public function handle() { - $de = new ChatLib(); - $en = new ChatLib(); + $count = 0; + $start = time(); + + $size = $this->argument('size'); + $lang = $this->argument('which'); + $db = new ChatLib($size); ChatLog::where('type', '=', 'chat') ->where('banned', '=', false) ->whereNotNull('evaluated_at') ->where('created_at', '<', now()->sub(7, 'day')) - ->chunk(5000, function ($msgs) use ($de, $en) { + ->whereNotIn('classification', ['gg', 'gl', 'number', 'o7']) + ->where(function ($query) use ($lang) { + $query->whereNull('detected_language'); + $query->orWhere('detected_language', '=', $lang); + }) + ->orderBy('channel_id') + ->orderBy('created_at') + ->chunk(5000, function ($msgs) use (&$count, $db) { + $previous = null; foreach ($msgs as $msg) { - if ($msg->detected_language === 'de') { - $de->addMessage($msg); - } else if ($msg->detected_language === 'en') { - $en->addMessage($msg); - } else if (is_null($msg->detected_language)) { - $de->addMessage($msg); - $en->addMessage($msg); - } + $db->addMessage($msg, $previous); + $previous = $msg; + ++$count; } + $this->line($count); }); - $de->compile(); - $de->saveAs('de'); + $db->compile(); + $db->saveAs($lang); - $en->compile(); - $en->saveAs('en'); + $this->line( + number_format(time() - $start, 0).'s '. + number_format(memory_get_usage() / 1024 / 1024, 3).'MB now '. + number_format(memory_get_peak_usage() / 1024 / 1024, 3).'MB peak'); return 0; }