Skip to main content

Repeated query

Optimize provides recommendations to help you identify and resolve performance issues caused by repeated queries.

The following query targeting the Post model is executed repeatedly with identical parameters:

await prisma.post.findMany({
where: {
published: true
},
take: 20
})

What is the problem?

When the same query is executed multiple times with the same parameters within a short time frame, it can lead to:

  • Time waste: A new connection may be established between the application and database, the query and its parameters are sent to the database, the database processes the query, and the results are sent back to the application.
  • Increased resource usage: Query execution increases CPU and memory usage, as well as disk I/O, putting strain on your database's system resources.
  • Higher costs: In serverless database pricing models, higher resource usage can result in increased costs.
info

To learn more about avoiding repeated queries with caching using Prisma Accelerate, refer to the Prisma Accelerate documentation.