Files
winter.liang c58565af77 fix: increase DB pool size and fix connection leak in permissions route
- connectionLimit 10 -> 50, queueLimit 0 -> 100 to prevent pool exhaustion
- Add missing db.release() in GET /permissions/:id finally block
2026-04-24 14:20:39 +08:00

35 lines
900 B
JavaScript

import mysql from 'mysql2/promise'
import { APP_TIMEZONE } from './config/db.js'
import dotenv from 'dotenv'
import path from 'path'
import { fileURLToPath } from 'url'
dotenv.config({ path: path.join(path.dirname(fileURLToPath(import.meta.url)), '.env') });
const db = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
port: process.env.DB_PORT,
waitForConnections: true,
connectionLimit: 50,
queueLimit: 100,
// timezone: '+08:00',
dateStrings: true,
});
const originalGetConnection = db.getConnection.bind(db);
db.getConnection = async () => {
const connection = await originalGetConnection();
// 设置时区
await connection.execute(`SET time_zone = '${APP_TIMEZONE}'`);
return connection;
};
export const getConnection = async () => {
return await db.getConnection()
}