3 namespace App\Console\Commands;
5 use App\Models\ChatLib;
6 use App\Models\ChatLog;
7 use Illuminate\Console\Command;
9 class ChatlibDatabase extends Command {
12 * The name and signature of the console command.
16 protected $signature = 'chatlib:database {which=de} {size=7}';
19 * The console command description.
23 protected $description = 'Update a ChatLib database';
26 * Execute the console command.
30 public function handle() {
34 $size = $this->argument('size');
35 $lang = $this->argument('which');
36 $db = new ChatLib($size);
38 ChatLog::where('type', '=', 'chat')
39 ->where('banned', '=', false)
40 ->whereNotNull('evaluated_at')
41 ->where('created_at', '<', now()->sub(7, 'day'))
42 ->whereNotIn('classification', ['gg', 'gl', 'number', 'o7'])
43 ->where(function ($query) use ($lang) {
44 $query->whereNull('detected_language');
45 $query->orWhere('detected_language', '=', $lang);
47 ->whereRaw('LENGTH(`text_content`) > 10')
48 ->chunk(5000, function ($msgs) use (&$count, $db) {
49 foreach ($msgs as $msg) {
50 $db->addMessage($msg);
60 number_format(time() - $start, 0).'s '.
61 number_format(memory_get_usage() / 1024 / 1024, 3).'MB now '.
62 number_format(memory_get_peak_usage() / 1024 / 1024, 3).'MB peak');