From aa244ef0e9038e167d7de996a53484dc9cc3b304 Mon Sep 17 00:00:00 2001 From: Alexander Alemayhu Date: Tue, 19 May 2026 18:17:33 +0200 Subject: [PATCH] perf: skip user lookup on SPA shell route MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../IndexController/IndexController.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/controllers/IndexController/IndexController.ts b/src/controllers/IndexController/IndexController.ts index 69d802364..caaab10c9 100644 --- a/src/controllers/IndexController/IndexController.ts +++ b/src/controllers/IndexController/IndexController.ts @@ -1,22 +1,11 @@ import express from 'express'; import { getDatabase } from '../../data_layer'; -import AuthenticationService from '../../services/AuthenticationService'; -import TokenRepository from '../../data_layer/TokenRepository'; -import UsersRepository from '../../data_layer/UsersRepository'; -import { configureUserLocal } from '../../routes/middleware/configureUserLocal'; import { sendIndex } from './sendIndex'; import { getDefaultEmailService } from '../../services/EmailService/EmailService'; class IndexController { - public getIndex(request: express.Request, response: express.Response) { - const database = getDatabase(); - const authService = new AuthenticationService( - new TokenRepository(database), - new UsersRepository(database) - ); - configureUserLocal(request, response, authService, database).then(() => { - sendIndex(response); - }); + public getIndex(_request: express.Request, response: express.Response) { + sendIndex(response); } async contactUs(req: express.Request, res: express.Response) {