update pool

This commit is contained in:
pringgosutono
2026-04-27 13:48:46 +07:00
parent 9dc6fec70e
commit aebdd509e2

View File

@ -43,33 +43,33 @@ pool.getConnection((err, conn) => {
// console.log('Connection %d released', connection.threadId);
// });
// --- The Deadlock Optimizer ---
// This function wraps your queries and retries them if a deadlock occurs
const queryWithRetry = async (sql, params, retries = 3) => {
for (let attempt = 1; attempt <= retries; attempt++) {
try {
return await pool.execute(sql, params);
} catch (err) {
const isDeadlock = err.code === 'ER_LOCK_DEADLOCK' || err.errno === 1213;
// // --- The Deadlock Optimizer ---
// // This function wraps your queries and retries them if a deadlock occurs
// const queryWithRetry = async (sql, params, retries = 3) => {
// for (let attempt = 1; attempt <= retries; attempt++) {
// try {
// return await pool.execute(sql, params);
// } catch (err) {
// const isDeadlock = err.code === 'ER_LOCK_DEADLOCK' || err.errno === 1213;
if (isDeadlock && attempt < retries) {
console.warn(`Deadlock detected. Retry attempt ${attempt}...`);
// Wait slightly longer each time (Exponential Backoff)
await new Promise(res => setTimeout(res, attempt * 100));
continue;
}
throw err; // If not a deadlock or out of retries, throw
}
}
};
// if (isDeadlock && attempt < retries) {
// console.warn(`Deadlock detected. Retry attempt ${attempt}...`);
// // Wait slightly longer each time (Exponential Backoff)
// await new Promise(res => setTimeout(res, attempt * 100));
// continue;
// }
// throw err; // If not a deadlock or out of retries, throw
// }
// }
// };
module.exports = {
pool,
query: queryWithRetry
};
// module.exports = {
// pool,
// query: queryWithRetry
// };
// module.exports = pool;
module.exports = pool;