fix: large transaction (#6695)

This commit is contained in:
darkskygit
2024-04-25 08:33:20 +00:00
parent 74b7d024be
commit ea3f427918
2 changed files with 77 additions and 73 deletions

View File

@@ -593,9 +593,8 @@ export const prompts: Prompt[] = [
]; ];
export async function refreshPrompts(db: PrismaClient) { export async function refreshPrompts(db: PrismaClient) {
await db.$transaction(async tx => {
for (const prompt of prompts) { for (const prompt of prompts) {
await tx.aiPrompt.upsert({ await db.aiPrompt.upsert({
create: { create: {
name: prompt.name, name: prompt.name,
action: prompt.action, action: prompt.action,
@@ -625,5 +624,4 @@ export async function refreshPrompts(db: PrismaClient) {
}, },
}); });
} }
});
} }

View File

@@ -13,7 +13,8 @@ export async function upgradeQuotaVersion(
// add new quota // add new quota
await upsertFeature(db, quota); await upsertFeature(db, quota);
// migrate all users that using old quota to new quota // migrate all users that using old quota to new quota
await db.$transaction(async tx => { await db.$transaction(
async tx => {
const latestQuotaVersion = await tx.features.findFirstOrThrow({ const latestQuotaVersion = await tx.features.findFirstOrThrow({
where: { feature: quota.feature }, where: { feature: quota.feature },
orderBy: { version: 'desc' }, orderBy: { version: 'desc' },
@@ -62,7 +63,12 @@ export async function upgradeQuotaVersion(
activated: true, activated: true,
})), })),
}); });
}); },
{
maxWait: 10000,
timeout: 20000,
}
);
} }
export async function upsertLatestQuotaVersion( export async function upsertLatestQuotaVersion(