Skip to content

Commit

Permalink
feat: add docs for new recommendations (DA-1498)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur-arch committed Oct 9, 2024
1 parent 52541ec commit bdfeccb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
32 changes: 32 additions & 0 deletions content/700-optimize/400-recommendations/400-repeated-query.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: 'Repeated query'
metaTitle: 'Optimize Recommendations: Repeated query'
metaDescription: "Learn about the recommendation provided by Optimize for repeated queries."
tocDepth: 3
toc: true
---

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

```ts
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](/accelerate/caching).

:::
29 changes: 29 additions & 0 deletions content/700-optimize/400-recommendations/500-select-returning.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: 'SELECT/RETURNING *'
metaTitle: 'Optimize Recommendations: `SELECT/RETURNING *`'
metaDescription: "Learn about the recommendation provided by Optimize for queries that are overfetching data."
tocDepth: 3
toc: true
---

The following query might be overfetching data in queries on the `user` model:

```ts
await prisma.user.findMany({
where: {
email: { contains: "gmail" },
},
include: {
links: true,
},
});
```

## What is the problem?

Retrieving data from all columns of a table, especially in large tables or those with complex relationships, can result in:

- **Increased load times**: Fetching more data than necessary prolongs query processing and data transfer times.
- **Greater resource consumption**: Retrieving unnecessary fields places strain on memory and CPU resources, both in the database and on the machines running your application.
- **Higher costs**: Reading and transferring excess data can lead to increased processing costs.
- **Security risks**: You might unintentionally expose sensitive data that should remain within the database.

0 comments on commit bdfeccb

Please sign in to comment.