fix: prevent Prisma connection pool exhaustion in production
Cache PrismaClient globally in ALL environments (was only cached in dev). Without this, production could create multiple PrismaClient instances, each with its own connection pool, exhausting the database connections. v1.71.2 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e1e31cef20
commit
92593cf616
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "my-weekly-todo-list",
|
||||
"version": "1.71.1",
|
||||
"version": "1.71.2",
|
||||
"description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@ -2,6 +2,15 @@ import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const globalForPrisma = global as unknown as { prisma: PrismaClient };
|
||||
|
||||
export const prisma = globalForPrisma.prisma || new PrismaClient();
|
||||
export const prisma =
|
||||
globalForPrisma.prisma ||
|
||||
new PrismaClient({
|
||||
datasources: {
|
||||
db: {
|
||||
url: process.env.DATABASE_URL,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;
|
||||
// Cache the client globally in ALL environments to prevent connection pool exhaustion
|
||||
globalForPrisma.prisma = prisma;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user