GET /tasks returns many records. A naive findMany() works for ten rows and falls over at ten million.
1const tasks = await prisma.task.findMany(); // ⚠️ returns the entire table
2return NextResponse.json({ data: tasks });Problems as data grows:
A production list endpoint controls:
where: { ownerId }).take).orderBy).1const tasks = await prisma.task.findMany({
2 where: { ownerId: session.userId },
3 orderBy: { createdAt: "desc" },
4 take: 20,
5});Clients need to know how to ask for more:
1const [data, total] = await Promise.all([
2 prisma.task.findMany({ where, orderBy, take: 20, skip }),
3 prisma.task.count({ where }),
4]);
5
6return NextResponse.json({
7 data,
8 meta: { total, pageSize: 20, page },
9});Never let a client request "all rows" by omitting a limit. Set a sensible default (e.g. 20) and a hard maximum (e.g. 100). Full pagination, filtering, sorting, and search get a whole chapter (Chapter 8).