From f03f3952254b7e23604ebba517783a26984aea2c Mon Sep 17 00:00:00 2001 From: Waleed Date: Tue, 7 Oct 2025 10:27:33 -0700 Subject: [PATCH] fix(db): enable database connection pooling in production (#1564) * fix: enable database connection pooling in production * debug: add diagnostic endpoints to test NODE_ENV and database pooling * test: add connection testing endpoint to diagnose production delay * redeuce num of concurrent connections --- apps/sim/socket-server/database/operations.ts | 3 +-- apps/sim/socket-server/rooms/manager.ts | 2 +- packages/db/index.ts | 12 ++---------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/apps/sim/socket-server/database/operations.ts b/apps/sim/socket-server/database/operations.ts index 388d6610a..09b25ced1 100644 --- a/apps/sim/socket-server/database/operations.ts +++ b/apps/sim/socket-server/database/operations.ts @@ -15,9 +15,8 @@ const socketDb = drizzle( prepare: false, idle_timeout: 10, connect_timeout: 20, - max: 25, + max: 15, onnotice: () => {}, - debug: false, }), { schema } ) diff --git a/apps/sim/socket-server/rooms/manager.ts b/apps/sim/socket-server/rooms/manager.ts index b36ac85a7..0e890761c 100644 --- a/apps/sim/socket-server/rooms/manager.ts +++ b/apps/sim/socket-server/rooms/manager.ts @@ -13,7 +13,7 @@ const db = drizzle( prepare: false, idle_timeout: 15, connect_timeout: 20, - max: 5, + max: 3, onnotice: () => {}, }), { schema } diff --git a/packages/db/index.ts b/packages/db/index.ts index d53999e08..7549eacbf 100644 --- a/packages/db/index.ts +++ b/packages/db/index.ts @@ -14,16 +14,8 @@ const postgresClient = postgres(connectionString, { prepare: false, idle_timeout: 20, connect_timeout: 30, - max: 80, + max: 30, onnotice: () => {}, }) -const drizzleClient = drizzle(postgresClient, { schema }) - -declare global { - // eslint-disable-next-line no-var - var database: PostgresJsDatabase | undefined -} - -export const db = globalThis.database || drizzleClient -if (process.env.NODE_ENV !== 'production') globalThis.database = db +export const db = drizzle(postgresClient, { schema })