2
0

Replace updates with updateManys when possible

Easy performance win to avoid triggering SELECT query after an UPDATE
This commit is contained in:
Baptiste Arnaud
2023-07-16 18:52:30 +02:00
parent 12ce4eb01b
commit 3426d6689d
13 changed files with 21 additions and 28 deletions

View File

@ -144,7 +144,7 @@ const sendAlertIfLimitReached = async (
chatsLimit,
url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`,
})
await prisma.workspace.update({
await prisma.workspace.updateMany({
where: { id: workspace.id },
data: { chatsLimitFirstEmailSentAt: new Date() },
})
@ -168,7 +168,7 @@ const sendAlertIfLimitReached = async (
chatsLimit,
url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`,
})
await prisma.workspace.update({
await prisma.workspace.updateMany({
where: { id: workspace.id },
data: { chatsLimitSecondEmailSentAt: new Date() },
})
@ -179,7 +179,7 @@ const sendAlertIfLimitReached = async (
if (totalChatsUsed > chatsLimit * 3 && workspace.plan === Plan.FREE) {
console.log(`Automatically quarantine workspace ${workspace.id}...`)
await prisma.workspace.update({
await prisma.workspace.updateMany({
where: { id: workspace.id },
data: { isQuarantined: true },
})