Skip to content

Commit f03f395

Browse files
authored
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
1 parent c2f0a95 commit f03f395

File tree

3 files changed

+4
-13
lines changed

3 files changed

+4
-13
lines changed

apps/sim/socket-server/database/operations.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ const socketDb = drizzle(
1515
prepare: false,
1616
idle_timeout: 10,
1717
connect_timeout: 20,
18-
max: 25,
18+
max: 15,
1919
onnotice: () => {},
20-
debug: false,
2120
}),
2221
{ schema }
2322
)

apps/sim/socket-server/rooms/manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const db = drizzle(
1313
prepare: false,
1414
idle_timeout: 15,
1515
connect_timeout: 20,
16-
max: 5,
16+
max: 3,
1717
onnotice: () => {},
1818
}),
1919
{ schema }

packages/db/index.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,8 @@ const postgresClient = postgres(connectionString, {
1414
prepare: false,
1515
idle_timeout: 20,
1616
connect_timeout: 30,
17-
max: 80,
17+
max: 30,
1818
onnotice: () => {},
1919
})
2020

21-
const drizzleClient = drizzle(postgresClient, { schema })
22-
23-
declare global {
24-
// eslint-disable-next-line no-var
25-
var database: PostgresJsDatabase<typeof schema> | undefined
26-
}
27-
28-
export const db = globalThis.database || drizzleClient
29-
if (process.env.NODE_ENV !== 'production') globalThis.database = db
21+
export const db = drizzle(postgresClient, { schema })

0 commit comments

Comments
 (0)