Dedupe the per-request session lookup - #5
Merged
Conversation
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.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
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 returnsnullfor 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:BalanceMeterscanned the whole roster to resolve a colour, once per member in the bar and again in the accessible label.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 buildand all 112 tests pass.