Fixes everything pointed out by Qudo

This commit is contained in:
Dum 2026-03-01 21:54:45 +05:30
parent a624b5a837
commit 5ee0f9cf98
5 changed files with 26 additions and 13 deletions

View file

@ -22,8 +22,9 @@ TMDB_API_KEY=''
TRAKT_CLIENT_ID=''
TRAKT_SECRET_ID=''
# Optional: PostgreSQL connection pool size (default: 100000)
# DB_POOL_MAX=100000
# Optional: PostgreSQL connection pool size (default: 1000)
# Is an integar, only set this for optimisation other wise leave blank
DB_POOL_MAX=
# Optional: Captcha
CAPTCHA=false

View file

@ -87,6 +87,8 @@ export default defineEventHandler(async event => {
});
});
if (upserts.length === 0) return [];
const bookmarks = await prisma.$transaction(upserts);
return bookmarks.map((bookmark: any) => ({

View file

@ -153,6 +153,8 @@ export default defineEventHandler(async event => {
})
);
if (upsertPromises.length === 0) return { success: true, count: 0, items: [] };
try {
const transactionResults = await prisma.$transaction(upsertPromises);

View file

@ -104,6 +104,8 @@ export default defineEventHandler(async event => {
});
});
if (upsertPromises.length === 0) return { success: true, count: 0, items: [] };
const transactionResults = await prisma.$transaction(upsertPromises);
const results = transactionResults.map(watchHistoryItem => ({

View file

@ -2,19 +2,25 @@ import { Pool } from 'pg';
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from '../../generated/client';
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
max: parseInt(process.env.DB_POOL_MAX || '1000', 10),
connectionTimeoutMillis: 10000,
idleTimeoutMillis: 300000,
});
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
pool: Pool | undefined;
};
const pool =
globalForPrisma.pool ||
new Pool({
connectionString: process.env.DATABASE_URL,
max: parseInt(process.env.DB_POOL_MAX || '1000', 10),
connectionTimeoutMillis: 10000,
idleTimeoutMillis: 300000,
});
const adapter = new PrismaPg(pool);
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
};
export const prisma = globalForPrisma.prisma || new PrismaClient({ adapter });
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;
if (process.env.NODE_ENV !== 'production') {
globalForPrisma.prisma = prisma;
globalForPrisma.pool = pool;
}