From 5355d8b7d2d14b9e54c87fa12ee5bcfe49ab22f3 Mon Sep 17 00:00:00 2001 From: ray <1416431931@qq.com> Date: Thu, 7 May 2026 10:08:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aliyun-sync/aliyun-aps-sync/.env.example | 1 + aliyun-sync/aliyun-aps-sync/src/config.js | 1 + aliyun-sync/aliyun-aps-sync/src/db.js | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/aliyun-sync/aliyun-aps-sync/.env.example b/aliyun-sync/aliyun-aps-sync/.env.example index 28b2ed5..9821f39 100644 --- a/aliyun-sync/aliyun-aps-sync/.env.example +++ b/aliyun-sync/aliyun-aps-sync/.env.example @@ -22,6 +22,7 @@ ALIYUN_APS_DB_PASSWORD= ALIYUN_APS_DB_NAME= ALIYUN_APS_DB_CHARSET=utf8mb4 ALIYUN_APS_DB_CONNECTION_LIMIT=5 +ALIYUN_APS_DB_CONNECT_TIMEOUT=20000 ALIYUN_APS_SMTP_HOST=smtp.163.com ALIYUN_APS_SMTP_PORT=465 ALIYUN_APS_SMTP_SECURE=true diff --git a/aliyun-sync/aliyun-aps-sync/src/config.js b/aliyun-sync/aliyun-aps-sync/src/config.js index 07ac23a..f853970 100644 --- a/aliyun-sync/aliyun-aps-sync/src/config.js +++ b/aliyun-sync/aliyun-aps-sync/src/config.js @@ -58,6 +58,7 @@ export const config = { database: process.env.ALIYUN_APS_DB_NAME || '', charset: process.env.ALIYUN_APS_DB_CHARSET || 'utf8mb4', connectionLimit: Math.max(1, Number.parseInt(process.env.ALIYUN_APS_DB_CONNECTION_LIMIT || '5', 10) || 5), + connectTimeout: Math.max(1000, Number.parseInt(process.env.ALIYUN_APS_DB_CONNECT_TIMEOUT || '20000', 10) || 20000), }, }; diff --git a/aliyun-sync/aliyun-aps-sync/src/db.js b/aliyun-sync/aliyun-aps-sync/src/db.js index f86487d..d08edb6 100644 --- a/aliyun-sync/aliyun-aps-sync/src/db.js +++ b/aliyun-sync/aliyun-aps-sync/src/db.js @@ -2,6 +2,7 @@ import mysql from 'mysql2/promise'; import { config } from './config.js'; let pool = null; +let customerMapCache = null; const MESSAGE_TABLE_DDL = ` CREATE TABLE IF NOT EXISTS aliyun_aps_messages ( @@ -52,6 +53,7 @@ function getPool() { database: config.db.database, charset: config.db.charset, connectionLimit: config.db.connectionLimit, + connectTimeout: config.db.connectTimeout, waitForConnections: true, }); return pool; @@ -130,6 +132,9 @@ function safeDateTime(value) { } async function getCustomerMap() { + if (customerMapCache) { + return customerMapCache; + } const [rows] = await getPool().query('SELECT account_id, login_name FROM aps_customer'); const map = new Map(); for (const row of rows) { @@ -141,7 +146,8 @@ async function getCustomerMap() { map.set(loginName, accountId); map.set(loginName.replace(/\s+/g, ''), accountId); } - return map; + customerMapCache = map; + return customerMapCache; } function resolveCustomerAccountId(customerMap, customerAccount) { @@ -186,6 +192,7 @@ export async function closeDbPool() { } await pool.end(); pool = null; + customerMapCache = null; } export async function ensureMessagesTable() {