mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-10-15 13:21:11 +00:00
7924794ae7
The @dokploy/server modules get bundled multiple times per process (esbuild inline copy, compiled node_modules copy, and several Next.js chunks via transpilePackages), so every module-level side effect ran once per copy: up to 6 postgres pools, 6 dockerode clients and 6 better-auth instances in the server process, plus the repeated 'Using Docker socket' logs at boot. - db/index.ts: use the globalThis cache in production too (one pool per process) - constants/index.ts: cache the dockerode client on globalThis - lib/auth.ts: wrap betterAuth() in a factory and cache the instance - Dockerfile: exec node directly instead of leaving pnpm resident (~100MB RSS)
28 lines
722 B
TypeScript
28 lines
722 B
TypeScript
import { and, eq } from "drizzle-orm";
|
|
import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
import postgres from "postgres";
|
|
import { dbUrl } from "./constants";
|
|
import * as schema from "./schema";
|
|
|
|
export { and, eq };
|
|
export * from "./schema";
|
|
|
|
type Database = PostgresJsDatabase<typeof schema>;
|
|
|
|
// Este módulo se evalúa varias veces por proceso (copias duplicadas por
|
|
// esbuild y los chunks de Next); el cache en globalThis garantiza un solo
|
|
// pool de conexiones por proceso.
|
|
const globalForDb = globalThis as unknown as {
|
|
db?: Database;
|
|
};
|
|
|
|
if (!globalForDb.db) {
|
|
globalForDb.db = drizzle(postgres(dbUrl), {
|
|
schema,
|
|
});
|
|
}
|
|
|
|
export const db: Database = globalForDb.db;
|
|
|
|
export { dbUrl };
|