From 7698b68aa5c4dc6b8b1d8d1e3eb38b700ce8b870 Mon Sep 17 00:00:00 2001 From: zasbu <136494048+zasbu@users.noreply.github.com> Date: Sat, 7 Nov 2026 14:43:48 +1100 Subject: [PATCH] Fetch a player's Steam profile after each new run A player's avatar and country were fetched from Steam only when they signed in or someone opened their profile, so players who just play showed initials and no flag everywhere they were listed: recently active players, boards, search. Their runs now keep the copy fresh too: after a new run is stored, a profile older than a day (or never fetched) is queued for a refresh. It uses the existing queue, so Steam still sees at most one request every 2 s and no more than 50 waiting, however busy the servers are. --- api/crates/api/src/runs.rs | 18 ++++++++++++++++++ docs/site-api.md | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/api/crates/api/src/runs.rs b/api/crates/api/src/runs.rs index dc2460e..5d1eb23 100644 --- a/api/crates/api/src/runs.rs +++ b/api/crates/api/src/runs.rs @@ -130,6 +130,24 @@ async fn submit_run( let stored = store(&mut tx, key, &run).await?; tx.commit().await?; + // A player is otherwise fetched from Steam only when they sign in or their profile is opened, so one who just + // plays would show initials everywhere they're listed. Their runs keep the copy fresh instead; the queue's + // spacing and cap keep this to Steam's pace however busy the servers are. + if stored.created { + let fetched_at = sqlx::query_scalar!( + "SELECT steam_profile_fetched_at FROM players WHERE steamid64 = $1", + run.player.steamid64.get() + ) + .fetch_one(&state.db) + .await?; + players::steam_profile::refresh_if_stale( + state.db.clone(), + state.steam.clone(), + run.player.steamid64, + fetched_at, + ); + } + let status = if stored.created { StatusCode::CREATED } else { diff --git a/docs/site-api.md b/docs/site-api.md index ff19725..03f78b9 100644 --- a/docs/site-api.md +++ b/docs/site-api.md @@ -13,7 +13,7 @@ Players sign in with Steam (OpenID 2.0); the endpoints answer browsers (redirect - Profiles take a SteamID64, SteamID2 or SteamID3 and answer with the SteamID64. Placements rank personal bests per map, style and track; equal times share a place. - Per style, a profile counts completed maps (main tracks, out of the map list's count), completed bonuses and world records, and carries the first 50 main-track personal bests by map; `…/personal-bests?style=&tracks=main|bonuses&cursor=` pages on, and `records=true` keeps only world records (2.0 only). Without `style` it lists every style, newest first; `all_styles` counts across styles. Ranks: `main_standing`, `bonus_standing` (lead, 2026-11-04). - `PUT /v1/players/{player}/details` (rules in `players/details.rs`): setup and a country (`GET /v1/countries`), a save per 5 s; others' need `manage_bans` and a logged reason. Old-site setup shows first. -- Avatar, country (unless the player picked one) and (until a run gives one) name come from their public Steam profile XML, fetched at sign-in and on viewing one over a day old (an hour after a failed one): one request per 2 s, 50 queued, one per player. Country names map to ISO codes in `players/countries.rs`. +- Avatar, country (unless the player picked one) and (until a run gives one) name come from their public Steam profile XML, fetched at sign-in, and when a day old after a run or a view (an hour after a failed one): one request per 2 s, 50 queued, one per player. Country names map to ISO codes in `players/countries.rs`. - Staff privileges are a bitmap in `players.privileges` (`players/privileges.rs`). Bit positions never change; the API names privileges and never sends numbers. `players.restrictions` is unused (bans hold restrictions). The CLI's `privileges grant …`, `revoke`, `list` and the staff tools share `staff/privileges.rs`. ## Maps and leaderboards