Skip to content

Dedupe the per-request session lookup - #5

Merged
BleakMidwinter90 merged 1 commit into
mainfrom
perf/dedupe-identity
Aug 10, 2026
Merged

Dedupe the per-request session lookup#5
BleakMidwinter90 merged 1 commit into
mainfrom
perf/dedupe-identity

Conversation

@BleakMidwinter90

Copy link
Copy Markdown
Owner

Follow-up from a review pass over the React/Next code.

The actual finding

getIdentity() ran twice on every authenticated page load. The home layout needs it to render the header, and each page beneath the layout needs the same identity to do its work — so every single request paid for the same three-table session join (sessions → members → households) twice over.

Wrapping it in React's cache() deduplicates it for the lifetime of a request. Nothing about its behaviour changes: it still reads the cookie, still runs the migration check, still returns null for archived members so a removed housemate is quietly signed out rather than shown an error.

This is the kind of thing that never shows up in a test — both calls return the correct answer — and would have quietly doubled the query load forever.

Also included

Two O(n·m) scans replaced with Maps built once:

  • BalanceMeter scanned the whole roster to resolve a colour, once per member in the bar and again in the accessible label.
  • The chores page scanned the roster per chore to resolve a fixed owner's name.

Households are small enough that neither was ever going to be measurable. They were just needless, and the Map version reads better.

Verified

npm run typecheck, eslint, next build and all 112 tests pass.

getIdentity() ran twice on every authenticated page load. The layout needs
it to render the header and each page beneath it needs the same identity,
so every request paid for the same three-table session join twice.

Wrapping it in React's cache() deduplicates it per request. Nothing else
changes: it still reads the cookie, still runs the migration check, still
returns null for archived members.

Also replaced two O(n*m) scans with Maps built once - member colours in
BalanceMeter (which scanned the roster twice per member) and the owner
name lookup on the chores page. Small households make these cheap either
way, but they were needless.

Typecheck, lint, build and 112 tests all pass.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@BleakMidwinter90
BleakMidwinter90 merged commit 8dbe5dd into main Aug 10, 2026
2 checks passed
@BleakMidwinter90
BleakMidwinter90 deleted the perf/dedupe-identity branch August 10, 2026 00:31
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.

1 participant