Default leaderboard to all maps

This commit is contained in:
2026-10-08 00:22:10 -04:00
parent 2f67482521
commit b42cbf1894
5 changed files with 14 additions and 61 deletions
-14
View File
@@ -32,20 +32,6 @@ export function isLeaderboardMetric(value: string): value is LeaderboardMetric {
return metrics.has(value);
}
/** Pick a usable initial map without ranking every player across the fleet first. */
export function defaultLeaderboardMap(options: Pick<LeaderboardOptions, 'game' | 'players'> = {}): string | null {
const conditions = ["m.game IN ('t5', 't6')", "m.status = 'completed'", `m.highest_round >= ${MIN_RECORDED_ROUND}`,
`EXISTS (SELECT 1 FROM leaderboard_match_players mp WHERE mp.match_id = m.id
AND mp.has_stats = 1 AND mp.highest_round >= ${MIN_RECORDED_ROUND})`];
const parameters: Array<string | number> = [];
if (options.game) { conditions.push('m.game = ?'); parameters.push(options.game); }
if (options.players) { conditions.push('m.start_players = ?'); parameters.push(options.players); }
const row = db().prepare(`SELECT m.map_key AS key FROM leaderboard_matches m
WHERE ${conditions.join(' AND ')} ORDER BY m.game, m.map_name COLLATE NOCASE, m.map_key, m.id DESC LIMIT 1`)
.get(...parameters) as { key: string } | undefined;
return row?.key ?? null;
}
/** Rank each GUID once within the selected matches; player search keeps their actual rank. */
export function getLeaderboard(options: LeaderboardOptions = {}): LeaderboardResponse {
return readLeaderboard(options);
+2 -19
View File
@@ -1,26 +1,9 @@
import { GET } from '../api/leaderboard/+server.js';
import { error, redirect } from '@sveltejs/kit';
import type { LeaderboardPlayerCount, LeaderboardResponse } from '$lib/leaderboard.js';
import { error } from '@sveltejs/kit';
import type { LeaderboardResponse } from '$lib/leaderboard.js';
import { leaderboardPageSize } from '$lib/leaderboard-updates.js';
import { defaultLeaderboardMap } from '$lib/server/fleet/leaderboard.js';
export async function load({ url }: { url: URL }) {
// A present empty map is the explicit All maps view. The API remains
// unfiltered by default for callers such as global player search.
if (!url.searchParams.has('map')) {
const game = url.searchParams.get('game');
const players = url.searchParams.get('players');
if (game !== null && game !== 't5' && game !== 't6' || players !== null && !/^[1-4]$/.test(players)) {
error(400, 'Use game t5 or t6 and players 1–4.');
}
const map = defaultLeaderboardMap({ game: game ?? undefined, players: players === null ? undefined : Number(players) as LeaderboardPlayerCount });
if (map) {
const destination = new URL(url);
destination.searchParams.set('map', map);
destination.searchParams.delete('offset');
redirect(307, destination.pathname + destination.search);
}
}
const reportUrl = new URL(url);
reportUrl.searchParams.set('limit', String(leaderboardPageSize));
const response = await GET({ url: reportUrl });