Skip to content

Commit

Permalink
feat: improve performance (esp. n+1) by batching requests
Browse files Browse the repository at this point in the history
Prisma will perform query optimizations at the engine level if multiple
similar queries are sent inside the same tick, by automatically batching
them together into a single larger query. This feature dramatically
improves performance for graphQL servers, avoiding the "n+1" problem.
By default, Prisma will batch requests by the transaction ID if it is present,
but this behaviour prevents automatic batching from working when using Yates, since all queries are executed inside an interactive transaction.
To get around this we by monkey patching the batching function to use the Yates ID as the batch ID.
To get the batching to work we also need to ensure that all the requests we might want to batch together are generated inside the same tick.
This means that all the requests per-tick that have the same role and context values will be batched together,
allowing the in-built prisma batch optimizations to work for us.
This is why we use process.nextTick and the tickActive flag to ensure we only tick once at a time.
See:
- https://github.com/prisma/prisma/blob/5.21.1/packages/client/src/runtime/RequestHandler.ts#L122
- https://www.prisma.io/docs/orm/prisma-client/queries/query-optimization-performance
  • Loading branch information
LucianBuzzo committed Nov 1, 2024
1 parent 2999b12 commit 0ff5d67
Show file tree
Hide file tree
Showing 7 changed files with 7,496 additions and 7,395 deletions.
7 changes: 5 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"files": {
"ignore": ["dist", "coverage"]
"ignore": ["dist", "coverage", "package.json"]
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
"recommended": true,
"suspicious": {
"noExplicitAny": "off"
}
}
}
}
Loading

0 comments on commit 0ff5d67

Please sign in to comment.