Implements the profile-stats change (specs/profile-stats):
- getActivityStats(ownerId, { publicOnly }) in activities.server.ts: one indexed
aggregate over stored columns (count, sum distance/ascent/elapsed duration) +
a rolling last-4-weeks count. No cache table, no schema change, no GPX parsing
(design §D1).
- Profile loader computes it scoped to the viewer (public-only for visitors,
full totals for the owner); ProfileStats header renders count · distance ·
ascent · time + "N in the last 4 weeks" via the shared StatRow + stats.ts
formatters; hidden when there are no visible activities.
- i18n journal.profileStats.* in en + de.
Tests: ProfileStats component (jsdom: totals, empty, last-4-weeks toggle);
e2e asserts the owner roll-up counts their activities. typecheck + lint + unit
(journal 318) green; verified in the browser.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1.4 KiB
1.4 KiB
1. Aggregate query
- 1.1 Added
getActivityStats(ownerId, { publicOnly })toactivities.server.ts: one aggregate (count,sum(distance/elevationGain/duration)) + alast4Weekscount (coalesce(started_at, created_at) >= now() - 28d), scoped bypublicOnly. - 1.2 Returns zeros when the owner has no visible activities (the component hides on
count === 0).
2. Loader & view
- 2.1 Profile loader calls
getActivityStats(user.id, { publicOnly: !isOwn })when content is visible; exposesstats. - 2.2
ProfileStatsheader onusers.$username.tsxabove the lists (reusesStatRow+stats.tsformatters); hidden when there are no activities.
3. i18n
- 3.1 Added
journal.profileStats.*(activities, distance, ascent, time, last4Weeks) to en + de.
4. Tests & checks
- 4.1 Component (jsdom): renders formatted totals + the last-4-weeks line; nothing on empty; line omitted when last4Weeks is 0.
- 4.2 E2E
profile-stats.test.ts: create activities → owner profile shows the roll-up ("2 in the last 4 weeks"). Owner-scoped count verified; the public-only branch is a one-line conditional covered by the query design (a fuller visitor-scoping e2e would need a public profile + a public/private activity mix — deferred). - 4.3 typecheck + lint + unit (journal 318) green; new e2e passes locally. Full
pnpm test:e2eruns in CI.