Simplify host overview and move enrollment into drawer
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { db } from '../db/index.js';
|
||||
import { listHosts } from './index.js';
|
||||
import { presentHostPreparation } from './preparation.js';
|
||||
import type { Host } from '../../hosts.js';
|
||||
|
||||
export interface HostOverview extends Host { serverCount: number }
|
||||
|
||||
/** Count assigned servers without loading their telemetry or historical placements. */
|
||||
export function hostOverview(): HostOverview[] {
|
||||
const hosts = listHosts();
|
||||
const counts = new Map((db().prepare(`SELECT i.host_id, COUNT(*) AS count FROM native_instances i
|
||||
JOIN servers s ON s.name = i.server
|
||||
WHERE i.retired_at IS NULL AND s.destroyed_at IS NULL
|
||||
GROUP BY i.host_id`).all() as { host_id: string; count: number }[]).map(row => [row.host_id, row.count]));
|
||||
return hosts.map(host => ({ ...presentHostPreparation(host), serverCount: counts.get(host.id) ?? 0 }));
|
||||
}
|
||||
Reference in New Issue
Block a user