Performance: Mongoose middleware (pre/post hooks)
MEDIUM IMPACT
This affects server response time and database operation speed by adding extra processing before or after database actions.
schema.pre('save', function(next) { if (this.isModified()) { next(); } else { next(); } });
schema.pre('save', async function() { await heavyComputation(); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous pre-save hook | N/A (server-side) | N/A | N/A | [X] Bad |
| Conditional lightweight pre-save hook | N/A (server-side) | N/A | N/A | [OK] Good |
| Blocking post-save hook with await | N/A (server-side) | N/A | N/A | [X] Bad |
| Asynchronous post-save hook with setImmediate | N/A (server-side) | N/A | N/A | [OK] Good |