festbench-web/app/Console/Commands/HomeSnapshot.php

72 lines
2.5 KiB
PHP
Raw Normal View History

<?php
namespace App\Console\Commands;
use App\Models\BenchmarkRun;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Symfony\Component\Console\Attribute\AsCommand;
#[AsCommand(name: 'festbench:snapshot', description: 'Rebuild the flat home_snapshot table (default home view, no UNION at request time)')]
class HomeSnapshot extends Command
{
private const ROWS = 500;
public function handle(): int
{
$rows = DB::table('all_results')
->join('benchmark_runs', 'benchmark_runs.id', '=', 'all_results.benchmark_run_id')
->where('benchmark_runs.visibility', BenchmarkRun::VISIBILITY_PUBLIC)
->orderByDesc('all_results.ran_at')
->orderByDesc('all_results.id')
->limit(self::ROWS)
->get([
'all_results.id',
'all_results.benchmark_run_id',
'all_results.ran_at',
'all_results.suite',
'all_results.task',
'all_results.level',
'all_results.ok',
'all_results.decode',
'all_results.user_tps',
'all_results.ttft',
'all_results.wall',
'all_results.total',
'benchmark_runs.run_id',
'benchmark_runs.model_id',
'benchmark_runs.model_quant',
]);
DB::transaction(function () use ($rows) {
DB::table('home_snapshot')->truncate();
foreach ($rows->values() as $index => $row) {
DB::table('home_snapshot')->insert([
'benchmark_run_id' => $row->benchmark_run_id,
'run_id' => $row->run_id,
'ran_at' => $row->ran_at,
'suite' => $row->suite,
'model_id' => $row->model_id,
'model_quant' => $row->model_quant,
'task' => $row->task,
'level' => $row->level,
'ok' => $row->ok,
'decode' => $row->decode,
'user_tps' => $row->user_tps,
'ttft' => $row->ttft,
'wall' => $row->wall,
'total' => $row->total,
'sequence' => $index,
'created_at' => now(),
'updated_at' => now(),
]);
}
});
$this->info('home_snapshot rebuilt: '.$rows->count().' rows.');
return self::SUCCESS;
}
}