Skip to content

Commit 51cefca

Browse files
fix(query): cache enable in frontend leaderboard
1 parent 3cf1750 commit 51cefca

1 file changed

Lines changed: 29 additions & 20 deletions

File tree

frontend/app.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ function sumTagKey(ts, k) {
179179

180180
function transform(row) {
181181
const ts = row.tag_stats || {};
182+
const n = (v) => v || 0; // coalesce so a field the API omits never renders as NaN
182183
const b = sumTagKey(ts, "building"),
183184
h = sumTagKey(ts, "highway");
184185
const lu = sumTagKey(ts, "landuse"),
@@ -191,19 +192,19 @@ function transform(row) {
191192
hashtags: row.hashtags || [],
192193
editors: row.editors || [],
193194
rank: row.rank,
194-
changesets: row.changesets,
195-
map_changes: row.map_changes,
196-
nodes_created: row.nodes_created,
197-
nodes_modified: row.nodes_modified,
198-
nodes_deleted: row.nodes_deleted,
199-
ways_created: row.ways_created,
200-
ways_modified: row.ways_modified,
201-
ways_deleted: row.ways_deleted,
202-
rels_created: row.rels_created,
203-
rels_modified: row.rels_modified,
204-
rels_deleted: row.rels_deleted,
205-
pois_created: row.poi_created,
206-
pois_modified: row.poi_modified,
195+
changesets: n(row.changesets),
196+
map_changes: n(row.map_changes),
197+
nodes_created: n(row.nodes_created),
198+
nodes_modified: n(row.nodes_modified),
199+
nodes_deleted: n(row.nodes_deleted),
200+
ways_created: n(row.ways_created),
201+
ways_modified: n(row.ways_modified),
202+
ways_deleted: n(row.ways_deleted),
203+
rels_created: n(row.rels_created),
204+
rels_modified: n(row.rels_modified),
205+
rels_deleted: n(row.rels_deleted),
206+
pois_created: n(row.poi_created),
207+
pois_modified: n(row.poi_modified),
207208
buildings_created: b.c,
208209
buildings_modified: b.m,
209210
highways_created: h.c,
@@ -218,9 +219,9 @@ function transform(row) {
218219
natural_modified: nt.m,
219220
amenities_created: am.c,
220221
amenities_modified: am.m,
221-
created: row.nodes_created + row.ways_created + row.rels_created,
222-
modified: row.nodes_modified + row.ways_modified + row.rels_modified,
223-
deleted: row.nodes_deleted + row.ways_deleted + row.rels_deleted,
222+
created: n(row.nodes_created) + n(row.ways_created) + n(row.rels_created),
223+
modified: n(row.nodes_modified) + n(row.ways_modified) + n(row.rels_modified),
224+
deleted: n(row.nodes_deleted) + n(row.ways_deleted) + n(row.rels_deleted),
224225
tag_stats: ts,
225226
};
226227
}
@@ -505,8 +506,11 @@ function freezeWindow() {
505506
function windowParams() {
506507
if (!state.windowStart || !state.windowEnd) freezeWindow();
507508
const p = new URLSearchParams();
508-
p.set("start", isoUTC(state.windowStart));
509-
p.set("end", isoUTC(state.windowEnd));
509+
// All-time omits the window: an explicit full range bypasses the API's all-time cache and warm.
510+
if (state.range !== "all") {
511+
p.set("start", isoUTC(state.windowStart));
512+
p.set("end", isoUTC(state.windowEnd));
513+
}
510514
return p;
511515
}
512516

@@ -584,6 +588,7 @@ async function runQuery() {
584588
state.editorStats = null;
585589
state.total = 0;
586590
setOverviewLoading();
591+
showLoading(); // skeleton the table now; the leaderboard fetch only starts after summary resolves
587592
$("#podium")?.closest("section")?.style.setProperty("display", "");
588593
$("#podium").innerHTML = "";
589594
if (typeof setChartsLoading === "function") setChartsLoading();
@@ -1129,7 +1134,11 @@ const cellsHtml = (cells, r) =>
11291134
.join("");
11301135

11311136
function openUserModal(username) {
1132-
const r = state.rows.find((x) => x.username === username);
1137+
// Podium holds the global top 3, which may not be on the current leaderboard page: search both.
1138+
const r =
1139+
state.rows.find((x) => x.username === username) ||
1140+
state.podium.find((x) => x.username === username) ||
1141+
state.batch.find((x) => x.username === username);
11331142
if (!r) return;
11341143
const modal = $("#user-modal");
11351144

@@ -1139,7 +1148,7 @@ function openUserModal(username) {
11391148

11401149

11411150
const subEl = $("#user-modal-sub");
1142-
subEl.textContent = `rank #${state.rows.findIndex((x) => x.username === username) + 1} · ${fmt.format(r.map_changes)} map changes · ${fmt.format(r.changesets)} changesets`;
1151+
subEl.textContent = `rank #${r.rank ?? "?"} · ${fmt.format(r.map_changes)} map changes · ${fmt.format(r.changesets)} changesets`;
11431152

11441153
const av = $("#user-modal-avatar");
11451154
av.style.background = avatarColor(r.username);

0 commit comments

Comments
 (0)