Show fresh player capacity on Fleet cards
This commit is contained in:
@@ -42,7 +42,7 @@ interface Record {
|
||||
/** A pass shares its reads; each asynchronous evidence boundary refreshes in one joined query. */
|
||||
export class MonitoringSnapshot {
|
||||
private records = new Map<string, Record>();
|
||||
constructor() { ensureHostSchema(db()); this.refresh(); }
|
||||
constructor(serverName?: string) { ensureHostSchema(db()); this.refresh(serverName); }
|
||||
refresh(server?: string): void {
|
||||
const rows = server === undefined ? db().prepare(sql + ' WHERE s.destroyed_at IS NULL ORDER BY s.name').all() as Row[]
|
||||
: db().prepare(sql + ' WHERE s.name=? AND s.destroyed_at IS NULL').all(server) as Row[];
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { PlayerCapacityObservation } from '../../server-capacity.js';
|
||||
import { monitoringStatus } from './health-observations.js';
|
||||
import { MonitoringSnapshot } from './monitoring-snapshot.js';
|
||||
|
||||
/** Read only the accepted, current-instance sample; never dispatch a probe. */
|
||||
export function observedPlayerCapacity(server: string, snapshot: MonitoringSnapshot): PlayerCapacityObservation {
|
||||
const game = monitoringStatus(server, snapshot)?.game;
|
||||
const capacity = game?.result.ok ? game.result.status.capacity : null;
|
||||
return typeof capacity === 'number' && Number.isSafeInteger(capacity) && capacity > 0
|
||||
? { capacity, capacity_observed_at: game!.observedAt }
|
||||
: { capacity: null, capacity_observed_at: null };
|
||||
}
|
||||
|
||||
/** One joined identity read for a fleet, or a single server on a detail route. */
|
||||
export function playerCapacityReader(serverName?: string) {
|
||||
const snapshot = new MonitoringSnapshot(serverName);
|
||||
return (server: string) => observedPlayerCapacity(server, snapshot);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { listHosts } from '../hosts/index.js';
|
||||
import type { NativeInstance } from '../backends/native.js';
|
||||
import { serverOperations } from './overview.js';
|
||||
import { hostListStatus } from '../../ui/host-overview.js';
|
||||
import { playerCapacityReader } from './player-capacity.js';
|
||||
|
||||
export function fleetSnapshot(serverName?: string) {
|
||||
const bindings = serverName === undefined ? [] : [serverName];
|
||||
@@ -27,12 +28,14 @@ export function fleetSnapshot(serverName?: string) {
|
||||
const entries = holds.get(row.server) ?? []; entries.push({ target: row.target, betaId: row.betaId }); holds.set(row.server, entries);
|
||||
}
|
||||
const observe = serverName === undefined ? observationReader() : serverObservation;
|
||||
const capacity = playerCapacityReader(serverName);
|
||||
const selected = serverName === undefined ? undefined : getServer(serverName);
|
||||
const rows = serverName === undefined ? listServers() : selected && !selected.destroyed_at ? [selected] : [];
|
||||
const servers = rows.map((s) => {
|
||||
const instance = s.native_instance_id ? instances.get(s.name) : null;
|
||||
return {
|
||||
...observe(s),
|
||||
...capacity(s.name),
|
||||
host: s.host_id ? hostsById.get(s.host_id) ?? null : null,
|
||||
network: instance ? { bindAddress: instance.bind_address, localPort: instance.port, publicAddress: instance.public_address, publicPort: instance.public_port } : null,
|
||||
plutonium: versions.get(s.name),
|
||||
|
||||
Reference in New Issue
Block a user