fix: show true lifetime totals in the Sessions widget#211
Merged
Conversation
The widget's "N sessions · Xh played" line was computed from the session LIST endpoint, which caps at SESSIONS_LIST_LIMIT (50) newest-first sessions. Heavy users therefore saw the count pinned at "50" and hours summing only the 50 newest sessions — a large undercount. Backend: add an `all_time` flag to GET /v1/me/stats/playtime (PlaytimeParams) so it aggregates over all history (since=None) instead of the bounded hours window (capped at 1 year). hours=0 in the response signals all-time. Frontend: the profile owner now fetches the all-time aggregate and the widget shows true lifetime session_count + playtime. Visitors (no me-scoped lifetime endpoint) fall back to the capped list, labelled "N+" so the number doesn't read as exact. Summary logic extracted to a pure buildSessionSummary() helper with unit tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Sessions widget's summary line ("N sessions · Xh played", labelled lifetime) was computed from the session list endpoint, which caps at
SESSIONS_LIST_LIMIT = 50newest-first sessions. So the count pinned at "50" and the hours only summed the 50 newest sessions — a large undercount for anyone who's played more (reported live on v1.8.52).Fix
Backend (
query.rs): add anall_timeflag toGET /v1/me/stats/playtime(newPlaytimeParams). When set, it aggregates over all history (since = None) instead of the boundedhourswindow (which is capped at 1 year and can't represent true lifetime).hours = 0in the response is the all-time sentinel. The underlyingtotal_playtime_secs(None)/count_sessions_since(None)already supported this — only the HTTP surface was missing it.Frontend: the profile owner now fetches the all-time aggregate and the widget shows true lifetime
session_count+ playtime. Visitors (no me-scoped lifetime endpoint exists) fall back to the capped list, labelledN+so the number doesn't read as exact. Summary logic extracted to a purebuildSessionSummary()with unit tests.Scope note
Owner-first by design (per discussion). Accurate lifetime totals for visitors viewing someone else's profile would need a new handle-scoped
/v1/users/{handle}/stats/playtime(sharing-auth) — deliberately deferred.Test plan
cargo test -p starstats-server— newstats_playtime_all_time_includes_sessions_outside_window(counts a 60-day-old session the default window excludes) + existing playtime test passcargo clippy -p starstats-serverclean;cargo fmt --checkcleanpnpm --filter web test:run— 248 pass incl. 4 newbuildSessionSummarycases (lifetime, 50+ cap label, exact count, singular)pnpm --filter web typecheck+lintcleanall_timequery param added)test.skip'd (NEXT_PUBLIC_PROFILE_WIDGETS not set in playwright.config) — no driftRoadmap-Item: game-running-detection-session-metrics-anti-cheat-safe