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

46 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace App\Console\Commands;
use App\Support\Suites;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Symfony\Component\Console\Attribute\AsCommand;
#[AsCommand(name: 'festbench:suites:refresh', description: 'Rebuild the all_results view from the active suite registry (decommission/add lever)')]
class SuitesRefresh extends Command
{
public function handle(): int
{
$suites = Suites::inAllResults();
if ($suites->isEmpty()) {
$this->warn('No active suites in the registry — skipping view rebuild.');
return self::SUCCESS;
}
$driver = DB::connection()->getDriverName();
$arms = $suites->map(fn (string $suite) => $this->arm($suite, $driver))->implode(' UNION ALL ');
DB::statement('DROP VIEW IF EXISTS all_results');
DB::statement("CREATE VIEW all_results AS {$arms}");
$this->info('all_results view rebuilt over: '.$suites->implode(', '));
return self::SUCCESS;
}
/**
* One UNION arm per suite. All metric tables share the core column set,
* so the arm promotes the suite name as a literal plus the common columns.
*/
private function arm(string $suite, string $driver): string
{
$table = Suites::modelFor($suite)::make()->getTable();
$quoted = $driver === 'pgsql' ? "'{$suite}'" : "'{$suite}'";
return "SELECT id, benchmark_run_id, ran_at, task, level, ok, decode, user_tps, ttft, t_answer, wall, reasoning, visible, total, finish, detail, {$quoted} AS suite FROM {$table}";
}
}