if prisma loop inside transaction send queries one time and if it really efficient?? #24498
-
Questionhello guys i need to ask question about prisma prisma.$transaction(async prisma=>{ How to reproduce (optional)Expected behavior (optional)No response Information about Prisma Schema, Client Queries and Environment (optional)// Add your schema.prisma// Add any relevant Prisma Client queries here
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
A database transaction limits all queries sent inside it to the same database connection, as a transaction can only live on one connection. So yes, all queries executed inside it are also executed sequentially, as one database connection can only execute one query at a time. |
Beta Was this translation helpful? Give feedback.
Inside a transaction, that is pretty much the only way. Apps usually read more data than they write, where not transactions are required, and there it makes total sense to send queries in parallel instead of sequentually.
If you are sending 100 queries in a loop, that is the problem. Find a way to combine these queries by for example collecting all the data in the loop first, and then sending one query instead.