perf: skip user lookup on SPA shell route#2461
Merged
Merged
Conversation
GET / and other non-/api routes serve a static React shell — sendIndex reads index.html from disk and writes it back unchanged. It never reads res.locals. The previous handler ran configureUserLocal first, which does up to 4 sequential database queries (user-by-token, isSubscriber, findActive pass, subscriptionInfo). The SPA fetches all that via /api/users/debug/locals after hydration anyway. Dropping the call removes the queries from the shell route and fixes a latent bug: configureUserLocal was chained via .then() without a .catch, so a thrown TokenExpiredError (visible in prod logs) silently never sent a response. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for notion2anki ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
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.



Summary
GET /and every non-/apiroute serve a static React shell —sendIndexreadsindex.htmlfrom disk and writes it back unchanged. It never readsres.locals.The previous handler ran
configureUserLocalfirst, which does up to 4 sequential database queries (user-by-token,isSubscriber,findActivepass,subscriptionInfo) on every page load. The SPA fetches user state via/api/users/debug/localsafter hydration anyway, so the work was wasted.This drops the call from the shell route only —
RequireAuthentication,RequirePaying, andRequireAllowedOriginmiddlewares still useconfigureUserLocalfor API routes that genuinely need user identity.Why this is also a bug fix
The previous code was:
No
.catch. WhenconfigureUserLocalthrew — e.g.TokenExpiredErroron a stale cookie, visible in prod logs right now — the response was never sent. The request just hung until the client timed out.Test plan
pnpm test src/controllers/IndexController— 10 tests passpnpm tsc --noEmitcleanhttps://2anki.net/and confirm TTFB drops (was ~150ms server-side; expect <50ms)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmithwith what you need.