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=3}';
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 ->orderBy('channel_id')
48 ->orderBy('created_at')
49 ->chunk(5000, function ($msgs) use (&$count, $db) {
51 foreach ($msgs as $msg) {
52 $db->addMessage($msg, $previous);
63 number_format(time() - $start, 0).'s '.
64 number_format(memory_get_usage() / 1024 / 1024, 3).'MB now '.
65 number_format(memory_get_peak_usage() / 1024 / 1024, 3).'MB peak');