logicsrc/apps/pwa/test
Anthony Ettinger fd253b0485
Some checks are pending
CI / build (push) Waiting to run
test / test (push) Waiting to run
perf(credshare): list a team's vaults in one query instead of two per vault (#128)
GET /api/credshare/teams/:slug/vaults built its response in a loop, asking
the database for a grant row and a secret count once per vault. libSQL is
remote, so each of those is a network round trip, and the endpoint cost
2N+1 of them.

On a team with 176 vaults that is 353 round trips and ~10.6s of server
time. `logicsrc teams pull` resolves the vault id twice -- once planning
the sync, once reading values -- so a pull of a single ten-key vault took
~24s, nearly all of it spent listing vaults the command does not want.

Replaced with one SELECT carrying two correlated subqueries. Both are
covered by existing primary keys (credshare_secrets is keyed
(vault_id, name), credshare_vault_grants (vault_id, user_id)), so the
per-vault work becomes an index probe inside the database instead of a
round trip across the network. No schema or index change.

Measured on a local libSQL seeded to match that team -- 176 vaults, 17
secrets each -- the endpoint goes from 355 round trips to 3, and returns
identical rows.

The response shape is unchanged: hasAccess is still a real boolean rather
than the 0/1 SQLite hands back, and secretCount is still a number.

Tests pin behaviour and cost separately. The behavioural cases pass
against both the old loop and the new query, which is the point -- only
the round-trip count changed. The regression guard asserts the query
count for 3 vaults EQUALS the count for 30 rather than matching a magic
number, so any future rewrite that reintroduces per-vault I/O fails no
matter what the constant part costs. Against the old loop it reports
9 vs 63.

Two sibling endpoints have the same shape -- /teams/:slug/members and
/vaults/:id/grants both call publicKeyFor() per member. Neither is on the
pull path and both scale with member count rather than vault count, so
they are left alone here.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-03 22:20:31 -07:00
..
appbar.test.mjs fix(pwa): unbreak sign-out, and stop echoing $PUBLIC_ORIGIN in the CLI hint (#108) 2026-07-30 10:56:36 -07:00
cli-hint.test.mjs fix(pwa): the CLI hint printed commands that no longer run 2026-07-30 11:43:33 -07:00
credshare-rekey.test.mjs feat(credentials): re-key team vaults, and reach sh1pt's vault as a provider (#117) 2026-07-30 18:41:03 -07:00
credshare-vaults.test.mjs perf(credshare): list a team's vaults in one query instead of two per vault (#128) 2026-08-03 22:20:31 -07:00
origin.test.mjs fix(pwa): return the caller's own host in the CLI device-flow URLs (#105) 2026-07-30 09:19:37 -07:00