Skip to content

Show sync activity per user (#7) - #34

Closed
beygorghor wants to merge 7 commits into
mainfrom
feat/user-activity
Closed

beygorghor wants to merge 7 commits into
mainfrom
feat/user-activity

Conversation

@beygorghor

Copy link
Copy Markdown
Contributor

Closes #7.

What changes

A Users entry in the left nav opens a page listing every user in the directory with, over a
switchable window of 7 days (the default), 30 days or 3 months: their number of syncs, total
submissions, distinct devices and last sync. Every column header sorts, and clicking it again
reverses. A user with no activity in the window keeps their row — zeros, an em-dash, dimmed —
because a supervisor looking for who went quiet needs to see them.

How it works

One SQL aggregate per window returns one row per user (41 of them); the browser re-sorts that
array in place, so only a change of window goes back to the server.

Two details in src/features/user-activity/api/queries.ts carry the whole query:

  • The window predicate sits in the on clause of a left join, not in a where. In a where it
    would drop exactly the inactive users the ticket is about. This is Django's FilteredRelation.
  • Every aggregate is cast ::int. Postgres returns count() as bigint, and pg hands bigint
    back as a string — measured: "6066" against 6066. Without the cast the table sorts "9"
    above "10" and nothing errors.

The window travels as an enum (7d / 30d / 90d); the server turns it into a cutoff date. The
query takes that date as a parameter rather than calling now(), so the tests pin the window
instead of racing the clock.

No migration: every column already exists.

New ADR

0015 — Cast aggregates to int in the SQL. It records the cast, rejects the alternative (a
global pg.types.setTypeParser), and states the uncomfortable part: PGlite returns an uncast
count() as a number, so no test can catch a missing cast. Review is the only check. ADR 0003
anticipated PGlite lacking something Neon has; this is the mirror image, where the test stays green.

What was checked

  • 57 tests pass, up from 44 (pnpm test), pnpm exec tsc --noEmit clean.
  • The query tests run on in-process Postgres and cover: a user who never synced, a user whose syncs
    all predate the window, repeat syncs from one device counted once, alphabetical order.
  • The table tests run in jsdom on props: default order, sorting and reversing, the em-dash, quiet
    users last in both directions, the empty state.
  • Against the real database: 41 users returned, 342 syncs over 7 days against 6,066 over 90.

One round of review found two real defects, both fixed here:

  • The sort test's fixture made syncCount order and alphabetical order identical, so a table that
    never left the username column passed it. New fixture (10 and 9) disagrees with the alphabet
    and with text ordering; mutating the comparator now fails it.
  • Switching the window unmounted the table and silently reset the sort. Fixed with
    placeholderData: keepPreviousData.

Worth knowing

  • The seed has no quiet user. Every one of the 41 users has synced within 7 days, so the dimmed
    row will not appear in the preview. ADR 0006 makes districts go silent, not users. The behaviour
    is covered by tests; it is just not demonstrable on seeded data.
  • Follow-ups deliberately not done here: asserting ::int in the compiled SQL (needs the builder
    exposed separately from the function that runs it), and moving relativeDays out of both table
    components into src/ui/ (it would edit device-syncs while other pairs are in it).

Spec: docs/superpowers/specs/2026-09-18-user-activity-design.md ·
Plan: docs/superpowers/plans/2026-09-18-user-activity.md

@vercel

vercel Bot commented Sep 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
wee-app Ready Ready Preview Sep 18, 2026 8:56am UTC

Request Review

@beygorghor beygorghor closed this Sep 18, 2026
plmercereau added a commit that referenced this pull request Sep 18, 2026
The preview of this branch was deleted when pull request #34 was closed,
and opening #35 on the same commit did not start a new one.

Claude-Session: https://claude.ai/code/session_01BLKZu4E8T123xzXASL2erH

This branch was successfully deployed

1 active deployment
Preview — d2761e31 Deployed Sep 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show sync activity per user

1 participant