Fix keyed telemetry match attribution (Refs #144)
CI / checks (push) Successful in 5m26s

This commit is contained in:
2026-10-12 00:58:05 -04:00
parent 4ea291d305
commit 785cc4616b
24 changed files with 1115 additions and 112 deletions
+18 -6
View File
@@ -15,6 +15,14 @@ export function listTelemetry(): GameTelemetry[] {
}
export function saveTelemetry(report: GameTelemetry): GameTelemetry {
return saveTelemetryWithOutcome(report).telemetry;
}
/** Acknowledgements retain their match id even when the live snapshot must stay put. */
export function saveTelemetryWithOutcome(report: GameTelemetry): {
telemetry: GameTelemetry;
current: boolean;
} {
// Keep callers outside the HTTP route atomic too.
const handle = db();
return handle.transaction(() => {
@@ -24,12 +32,16 @@ export function saveTelemetry(report: GameTelemetry): GameTelemetry {
const previous: GameTelemetry | undefined = row?.payload
? JSON.parse(row.payload)
: undefined;
recordLeaderboardTelemetry(handle, report);
const recorded = recordLeaderboardTelemetry(handle, report);
if (!recorded.current) {
return {
telemetry: { ...report, timing: { matchId: recorded.matchId, players: {} } },
current: false
};
}
const match = handle
.prepare(
'SELECT id, started_at, start_observed FROM leaderboard_matches WHERE server = ? ORDER BY id DESC LIMIT 1'
)
.get(report.server) as { id: number; started_at: string; start_observed: number };
.prepare('SELECT id, started_at, start_observed FROM leaderboard_matches WHERE id = ?')
.get(recorded.matchId) as { id: number; started_at: string; start_observed: number };
const sameMatch = previous?.timing?.matchId === match.id;
const serverTiming = handle
.prepare(
@@ -128,6 +140,6 @@ export function saveTelemetry(report: GameTelemetry): GameTelemetry {
)
.run(report.receivedAt, report.server, report.receivedAt);
}
return report;
return { telemetry: report, current: true };
})();
}