1. Nested include fan-out
Symptom
One `findMany` in the code. Six queries and a large payload in the logs.
The pattern
const orgs = await db.org.findMany({
include: {
users: { include: { posts: { include: { comments: true } } } },
},
});Why it bites
Prisma resolves each relation level as a separate query and joins in memory. Three levels across a hundred orgs materializes every comment for every post for every user — usually to render a count. Payload size, not query time, is what breaks it.
The fix
// Ask for the shape you actually render.
const orgs = await db.org.findMany({
select: {
id: true,
name: true,
_count: { select: { users: true } }, // aggregate in the database
},
});