-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add docs for new recommendations (DA-1498)
- Loading branch information
1 parent
52541ec
commit bdfeccb
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
content/700-optimize/400-recommendations/400-repeated-query.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
content/700-optimize/400-recommendations/500-select-returning.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |