added option for impact route to return a specific map with ?mapName parameter

This commit is contained in:
jenz
2026-10-04 16:30:53 +02:00
parent 8a76454784
commit 7a6051987e
2 changed files with 31 additions and 4 deletions
@@ -235,14 +235,23 @@ export async function getMapImpactLeaderboard(
direction: 'asc' | 'desc',
limit = 50,
offset = 0,
mapNames?: string[],
): Promise<MapImpactSummary[]> {
const all = await getMapImpactStatsCached();
const filtered = mapNames && mapNames.length > 0
? (() => {
const wanted = new Set(mapNames.map((n) => n.toLowerCase()));
return all.filter((m) => wanted.has(m.map_name.toLowerCase()));
})()
: all;
const sign = direction === 'asc' ? 1 : -1;
const sorted = [...all].sort((a, b) => {
const sorted = [...filtered].sort((a, b) => {
const av = sortBy === 'popularity' ? a.times_played : a.avg_net_change ?? 0;
const bv = sortBy === 'popularity' ? b.times_played : b.avg_net_change ?? 0;
if (av !== bv) return sign * (av - bv);
return b.times_played - a.times_played; // stable tiebreaker, matches old ORDER BY ..., times_played DESC
});
return sorted.slice(offset, offset + limit);
// When specific map names are requested, return all matches rather than
// paginating — the caller asked for those exact maps, not a page of them.
return mapNames && mapNames.length > 0 ? sorted : sorted.slice(offset, offset + limit);
}