Move to a single prisma client connection for the ui backend to prevent competing connections.
This commit is contained in:
16
ui/src/server/prisma.ts
Normal file
16
ui/src/server/prisma.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
// Single shared PrismaClient for the whole server. Route files must import
|
||||
// this instead of constructing their own client — each PrismaClient spawns
|
||||
// its own query engine + connection pool, and a pile of them contending for
|
||||
// the same sqlite file just adds lock pressure. The globalThis stash keeps
|
||||
// dev hot-reload from leaking a new client on every recompile.
|
||||
const globalForPrisma = globalThis as unknown as { prisma?: PrismaClient };
|
||||
|
||||
const prisma = globalForPrisma.prisma ?? new PrismaClient();
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
globalForPrisma.prisma = prisma;
|
||||
}
|
||||
|
||||
export default prisma;
|
||||
@@ -1,10 +1,9 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import prisma from '@/server/prisma';
|
||||
import { defaultDatasetsFolder, defaultDataRoot } from '@/paths';
|
||||
import { defaultTrainFolder } from '@/paths';
|
||||
import NodeCache from 'node-cache';
|
||||
|
||||
const myCache = new NodeCache();
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export const flushCache = () => {
|
||||
myCache.flushAll();
|
||||
|
||||
Reference in New Issue
Block a user