fix: cap postgres connection pools

This commit is contained in:
Codex
2026-05-15 00:18:42 +00:00
parent c930607316
commit c206f13216
10 changed files with 47 additions and 8 deletions
@@ -17,6 +17,7 @@ interface RuntimeConfig {
port: number;
databaseUrl: string;
logFile: string;
databasePoolMax: number;
clientId: string;
clientSecret: string;
tokenKey: string;
@@ -113,6 +114,7 @@ function configFromEnv(): RuntimeConfig {
port: Number(process.env.PORT || 4244),
databaseUrl,
logFile: process.env.LOG_FILE || "",
databasePoolMax: Math.max(1, Math.min(8, Number(process.env.DATABASE_POOL_MAX || 2) || 2)),
clientId: process.env.BAIDU_NETDISK_CLIENT_ID || process.env.BAIDU_NETDISK_APP_KEY || "",
clientSecret: process.env.BAIDU_NETDISK_CLIENT_SECRET || process.env.BAIDU_NETDISK_SECRET_KEY || "",
tokenKey: process.env.BAIDU_NETDISK_TOKEN_KEY || "",
@@ -124,7 +126,12 @@ function configFromEnv(): RuntimeConfig {
}
const config = configFromEnv();
const sql = postgres(config.databaseUrl, { max: 8, idle_timeout: 20, connect_timeout: 10 });
const sql = postgres(config.databaseUrl, {
max: config.databasePoolMax,
idle_timeout: 20,
connect_timeout: 10,
connection: { application_name: "unidesk-baidu-netdisk" },
});
const logWriter = config.logFile
? createHourlyJsonlWriter({
baseLogFile: config.logFile,