Add performance regression detection: indexes, timing middleware, benchmark script
Nightshift-Task: perf-regression Nightshift-Ref: https://github.com/marcus/nightshift
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
"start": "node src/index.js",
|
||||
"dev": "nodemon src/index.js",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest"
|
||||
"test:watch": "vitest",
|
||||
"perf": "node ../scripts/perf-benchmark.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
|
||||
@@ -9,11 +9,13 @@ const actualsRouter = require('./routes/actuals');
|
||||
const oneTimeExpensesRouter = require('./routes/one-time-expenses');
|
||||
const summaryRouter = require('./routes/summary');
|
||||
const { router: financingRouter } = require('./routes/financing');
|
||||
const timingMiddleware = require('./middleware/timing');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(timingMiddleware);
|
||||
|
||||
// API routes
|
||||
app.use('/api', healthRouter);
|
||||
|
||||
21
server/src/middleware/timing.js
Normal file
21
server/src/middleware/timing.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
const SLOW_THRESHOLD_MS = 200;
|
||||
|
||||
function timingMiddleware(req, res, next) {
|
||||
const start = Date.now();
|
||||
|
||||
res.on('finish', () => {
|
||||
const duration = Date.now() - start;
|
||||
const msg = `${req.method} ${req.path} ${res.statusCode} ${duration}ms`;
|
||||
if (duration >= SLOW_THRESHOLD_MS) {
|
||||
console.warn(`[SLOW] ${msg}`);
|
||||
} else {
|
||||
console.log(`[timing] ${msg}`);
|
||||
}
|
||||
});
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = timingMiddleware;
|
||||
Reference in New Issue
Block a user