PrismaP
Prisma2y ago
4 replies
Lady Gaga

Optimizing a query

I currently have the following code to update the pricing of the items in the database:
const prismapromises = Object.keys(items).map((item) =>
  prisma.minion.update({
    where: { id: item },
    data: { cost: items[items] }
  })
);

await prisma.$transaction(prismapromises);


This is a cron job that runs every day and I have 700 items. So every day, 700 queries are being executed.
This is not great, especially since I'm using Accelerate as this costs 21000 queries a month (700 * 30).
I don't know how to optimize this, since updateMany doesn't work with multiple different id's.

Any help would be great!
Was this page helpful?