#Update performance issue when performing many single update() operations

7 messages · Page 1 of 1 (latest)

serene mango
#

I'm having big performance issues trying to update many rows inside a transaction here's the code:

I tried to parallelise the updates with a Promise.all but no improvements.

I have about 50 elements in data and it takes an astonishing 4 seconds to do such a simple update.

Note: I cannot use the updateMany because I need to update each rows with specific data, I used Total: 1234 here to simplify the example

await prisma.$transaction(async (t) => {
    const promises = data.map((d) => {
        return prismaClient.myTable.update({
            where: { ID: d.ID },
            data: {
                Total: 1234,
            },
        });
    });

    await Promise.all(promises);
});
frosty bobcatBOT
#

You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!

serene mango
#

I realized that I could use updateMany to nearly double the speed. Probably because there is no return of the entity after an updateMany

#

Any other improvements that can be done?

candid pebble
#

db calls in transactions run on a single connection

#

so Promise.all() has no effect

waxen elbow
#

Did you see any improvements after using updateMany?