Performance Issue: No Index on Email/Username Lookup Fields
Description
User lookup queries (login, profile fetch, session validation) perform full collection/table scans because the email and username fields lack database indexes. With a growing user base, this causes response time degradation on every authenticated request.
Steps to Reproduce
- Insert 10,000+ user records into the database
- Enable query explain/analyze (MongoDB:
db.users.find({email: 'x'}).explain("executionStats"))
- Observe:
COLLSCAN (full collection scan) instead of IXSCAN (index scan)
- Execution time scales linearly with user count
Root Cause
The user model/schema does not define indexes on frequently queried fields.
Impact
- Login response time of 100ms+ per query at scale
- Every page requiring authentication triggers at least one user lookup
- Database becomes the bottleneck under moderate traffic
Proposed Fix
Add unique indexes to the user model:
// Mongoose schema
const userSchema = new Schema({
email: { type: String, required: true, unique: true, index: true },
username: { type: String, required: true, unique: true, index: true },
// ...
});
The unique: true constraint also implicitly creates an index. For compound queries, add a compound index.
I would like to implement this and add a migration script if assigned.
Performance Issue: No Index on Email/Username Lookup Fields
Description
User lookup queries (login, profile fetch, session validation) perform full collection/table scans because the
emailandusernamefields lack database indexes. With a growing user base, this causes response time degradation on every authenticated request.Steps to Reproduce
db.users.find({email: 'x'}).explain("executionStats"))COLLSCAN(full collection scan) instead ofIXSCAN(index scan)Root Cause
The user model/schema does not define indexes on frequently queried fields.
Impact
Proposed Fix
Add unique indexes to the user model:
The
unique: trueconstraint also implicitly creates an index. For compound queries, add a compound index.I would like to implement this and add a migration script if assigned.