Description
What happened?
Every API request from a signed-in browser updates that user's document in the sessions collection, and the response waits for the write.
On each request that leaves the session unchanged, express-session calls store.touch() to push its expiry forward. connect-mongo's touch() runs an updateOne unless touchAfter is set, and api-app.ts doesn't set it. So a dashboard or search page rewrites the same session document once for every chart query and other API call it makes.
Measured in the integration environment (API and MongoDB on the same machine), signed-in GET /me, two runs each:
main |
touchAfter: 1h |
|
|---|---|---|
| Session writes, 300 sequential requests | 300 | 0 |
| Session writes, 250 parallel requests | 250 | 0 |
| Sequential latency | 3.27 ms/req | 2.41 ms/req |
| 10 rounds × 25 parallel requests, p95 | 38.5 ms | 24.5 ms |
The gap should be larger against a remote MongoDB or DocumentDB, where each write is a network round trip.
Steps to reproduce
yarn dev, sign in.mongosh "<MONGO_URI>" --eval 'db.sessions.find({}, { expires: 1 })'- Open any dashboard and run step 2 again:
expireshas moved. It moves on every API request.
Proposed fix
Set touchAfter to one hour, and backfill lastModified on existing sessions so the change also applies to users who are already signed in.
Activity
[-]API writes the login session to MongoDB on every request[/-][+]perf : API writes the login session to MongoDB on every request[/+][-]perf : API writes the login session to MongoDB on every request[/-][+]perf(api) : API writes the login session to MongoDB on every request[/+]Aryainguz commentedon Nov 26, 2026
didn't flag it as bug, since I think its more of a performance optimization