⚡ Replace updates with updateManys when possible
Easy performance win to avoid triggering SELECT query after an UPDATE
This commit is contained in:
@@ -36,11 +36,6 @@ export const getUsage = authenticatedProcedure
|
||||
|
||||
const now = new Date()
|
||||
const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 1)
|
||||
const firstDayOfNextMonth = new Date(
|
||||
now.getFullYear(),
|
||||
now.getMonth() + 1,
|
||||
1
|
||||
)
|
||||
const [
|
||||
totalChatsUsed,
|
||||
{
|
||||
@@ -62,7 +57,6 @@ export const getUsage = authenticatedProcedure
|
||||
hasStarted: true,
|
||||
createdAt: {
|
||||
gte: firstDayOfMonth,
|
||||
lt: firstDayOfNextMonth,
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -48,7 +48,7 @@ const updateTokens =
|
||||
access_token: credentials.access_token,
|
||||
}
|
||||
const { encryptedData, iv } = await encrypt(newCredentials)
|
||||
await prisma.credentials.update({
|
||||
await prisma.credentials.updateMany({
|
||||
where: { id: credentialsId },
|
||||
data: { data: encryptedData, iv },
|
||||
})
|
||||
|
||||
@@ -216,7 +216,7 @@ const updateLastActivityDate = async (user: User) => {
|
||||
first.getDate() === second.getDate()
|
||||
|
||||
if (!datesAreOnSameDay(user.lastActivityAt, new Date()))
|
||||
await prisma.user.update({
|
||||
await prisma.user.updateMany({
|
||||
where: { id: user.id },
|
||||
data: { lastActivityAt: new Date() },
|
||||
})
|
||||
|
||||
@@ -104,7 +104,7 @@ const webhookHandler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
data: { claimedAt: new Date() },
|
||||
})
|
||||
|
||||
await prisma.workspace.update({
|
||||
await prisma.workspace.updateMany({
|
||||
where: { id: workspaceId },
|
||||
data: {
|
||||
plan: Plan.CUSTOM,
|
||||
|
||||
Reference in New Issue
Block a user