Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add optimize docs #6159

Merged
merged 74 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
b0d0621
feat: add optimize to the sidebar
ankur-arch Jul 22, 2024
6ad6b78
feat: add optimize in the getting started section
ankur-arch Jul 22, 2024
d1035a4
fix: add optimize url
ankur-arch Jul 22, 2024
c8b8f6a
feat: add optimize docs
ankur-arch Jul 22, 2024
49fd29e
fix: add optimize icons
ankur-arch Jul 25, 2024
0408abe
feat: add more sections to optmize docs
ankur-arch Jul 25, 2024
b5cbec8
feat: add optimize to footer
ankur-arch Jul 25, 2024
1258dda
feat: add note on using optimize
ankur-arch Jul 25, 2024
8f35f27
fix: correct spelling for usecase
ankur-arch Jul 25, 2024
19fd3ac
feat: add more on indexes
ankur-arch Jul 25, 2024
1c8969e
Merge branch 'main' into optimize-docs
carlagn Aug 12, 2024
ed9401b
Update content/700-optimize/200-getting-started.mdx
ankur-arch Aug 13, 2024
5342d35
Update content/700-optimize/400-recommendations.mdx
ankur-arch Aug 13, 2024
acb1e7e
Update content/700-optimize/400-recommendations.mdx
ankur-arch Aug 13, 2024
b9d9ac9
Update content/700-optimize/400-recommendations.mdx
ankur-arch Aug 13, 2024
3447227
Update content/700-optimize/400-recommendations.mdx
ankur-arch Aug 13, 2024
fe9229c
Update content/700-optimize/200-getting-started.mdx
ankur-arch Aug 13, 2024
2ecc73e
Update content/700-optimize/200-getting-started.mdx
ankur-arch Aug 13, 2024
0696c55
Update content/700-optimize/200-getting-started.mdx
ankur-arch Aug 13, 2024
426af9a
Update content/700-optimize/200-getting-started.mdx
ankur-arch Aug 13, 2024
248fa27
Update content/700-optimize/200-getting-started.mdx
ankur-arch Aug 13, 2024
8ef853f
Merge branch 'main' into optimize-docs
ankur-arch Aug 13, 2024
4fa870b
feat: add enhancements on recommendations
ankur-arch Aug 13, 2024
9676e16
Update content/700-optimize/200-getting-started.mdx
ankur-arch Aug 13, 2024
bf8d19f
Update content/700-optimize/300-recording.mdx
ankur-arch Aug 13, 2024
9ca80d5
Update content/700-optimize/300-recording.mdx
ankur-arch Aug 13, 2024
d53f231
fix: rename file to recordings
ankur-arch Aug 13, 2024
ca12e21
Update ormLinkSectionWrapper
carlagn Aug 13, 2024
983b46e
Merge branch 'main' into optimize-docs
ankur-arch Aug 19, 2024
ae25dd8
feat: add ai explainer section to the docs
ankur-arch Aug 19, 2024
4d8554f
feat: add ai limitations for optimize
ankur-arch Aug 19, 2024
43d9b05
feat: add more faq items
ankur-arch Aug 19, 2024
17da7c2
Merge branch 'main' into optimize-docs
ankur-arch Aug 20, 2024
2675a83
feat: new content changes
ankur-arch Aug 21, 2024
c856ea6
fix: remove random line
ankur-arch Aug 21, 2024
ddc8b7d
fix: optimize api key section
ankur-arch Aug 21, 2024
282ee28
feat: improve getting started section
ankur-arch Aug 21, 2024
48239a8
fix: add more feedback
ankur-arch Aug 21, 2024
4722a74
fix: broken link on ai-explainer
ankur-arch Aug 21, 2024
e62d472
Merge branch 'main' into optimize-docs
ankur-arch Aug 21, 2024
5eda3a7
feat: add ms sql server to optimize
ankur-arch Aug 22, 2024
81df09f
feat: update optimize url
ankur-arch Sep 5, 2024
a3df33a
Merge branch 'main' into optimize-docs
ankur-arch Sep 5, 2024
ff6dfb5
feat: update API key getting steps
ankur-arch Sep 5, 2024
f2bbb8f
Update content/700-optimize/200-getting-started.mdx
ankur-arch Sep 6, 2024
eb4b8ce
Update content/100-getting-started/index.mdx
ankur-arch Sep 6, 2024
5b3dfa0
Update content/100-getting-started/index.mdx
ankur-arch Sep 6, 2024
9da0c0f
Update content/700-optimize/index.mdx
ankur-arch Sep 8, 2024
45d7758
Update content/700-optimize/200-getting-started.mdx
ankur-arch Sep 8, 2024
87cf0b0
feat: move optimize
ankur-arch Sep 8, 2024
23b04a2
Merge branch 'main' into optimize-docs
ankur-arch Sep 8, 2024
641c1fa
fix: replace to prisma ai
ankur-arch Sep 8, 2024
cb5e436
fix: paraphrase to be more accurate
ankur-arch Sep 8, 2024
b53a0db
fix: clear recommendations page
ankur-arch Sep 8, 2024
8fc859a
enhance: add links
ankur-arch Sep 8, 2024
ac6a4c9
feat: more specific instructions
ankur-arch Sep 8, 2024
b9bc658
feat: add prisma queries
ankur-arch Sep 8, 2024
b53726b
feat: add more limitations
ankur-arch Sep 8, 2024
7291494
Update content/700-optimize/index.mdx
jharrell Sep 8, 2024
2c22fef
Update content/700-optimize/index.mdx
ankur-arch Sep 9, 2024
02c2c5b
Update content/700-optimize/400-recommendations/300-full-table-scans-…
ankur-arch Sep 9, 2024
968c444
Update content/700-optimize/400-recommendations/200-queries-on-uninde…
ankur-arch Sep 9, 2024
19d8cf5
Update content/700-optimize/200-getting-started.mdx
ankur-arch Sep 9, 2024
3fab0f5
Update content/700-optimize/200-getting-started.mdx
ankur-arch Sep 9, 2024
ebbf20b
Update content/700-optimize/200-getting-started.mdx
ankur-arch Sep 9, 2024
371585e
Update content/700-optimize/200-getting-started.mdx
ankur-arch Sep 9, 2024
78aa10f
Update content/700-optimize/400-recommendations/100-excessive-number-…
ankur-arch Sep 9, 2024
749bd21
fix: update performance page
ankur-arch Sep 9, 2024
a06949c
feat: add a limitation and an faq
ankur-arch Sep 9, 2024
ae39e16
Update content/700-optimize/index.mdx
jharrell Sep 9, 2024
321834a
Merge branch 'main' into optimize-docs
jharrell Sep 9, 2024
546b91c
feat: add callout #DA-1328
ankur-arch Sep 9, 2024
6b93aca
feat: make callout the main focus in getting started
ankur-arch Sep 9, 2024
5cb25c8
fix: add links
ankur-arch Sep 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
"Nikolas",
"Supavisor",
"inshellisense",
"janedoe"
"janedoe",
"unindexed"
],
"patterns": [
{
Expand Down
22 changes: 22 additions & 0 deletions content/100-getting-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Bolt,
BorderBox,
BoxTitle,
Inspect,
Database,
Grid,
LinkCard,
Expand All @@ -38,6 +39,8 @@ Explore our products that make it easy to build and scale data-driven applicatio
[**<SignalStream />Prisma Pulse**](/pulse) allows you to react to database changes with type-safe model streams in real-time.


[**<Inspect />Prisma Optimize**](/optimize/what-is-optimize) helps you to analyze queries, generate insights and provides recommendations that can be used to make your database queries faster.

</BorderBox>

</TopBlock>
Expand Down Expand Up @@ -195,3 +198,22 @@ Build real-time applications by subscribing to data changes in your database usi
link="https://github.com/prisma/prisma-examples?tab=readme-ov-file#prisma-pulse"
/>
</Grid>

## <Inspect color="#16A394" width="27" height="24" /> Prisma Optimize

Make your database queries faster by using the insights and recommendations generated by Prisma Optimize.

<Grid>
<LinkCard
icon="fa-solid fa-arrow-right"
title="Get started"
desc="Add Optimize to your app to generate useful insights and recommendations to improve query performance."
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
link="/optimize/getting-started"
/>
<LinkCard
icon="fa-brands fa-github"
title="Examples"
desc="Explore our ready-to-run examples using Optimize."
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
link="https://github.com/prisma/prisma-examples?tab=readme-ov-file#prisma-optimize"
/>
</Grid>
meletj marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ tocDepth: 3

This guide describes ways to optimize query performance, debug performance issues, and how to tackle common performance issues such as the [n+1 problem](#solving-the-n1-problem).

:::note

You can also use [Prisma Optimize](/optimize) to debug slow queries and follow the [recommendations](/optimize/recommendations) provided to improve query performance in your app.
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved

:::

</TopBlock>

## Debugging performance issues
Expand Down
21 changes: 21 additions & 0 deletions content/700-optimize/100-what-is-optimize.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: 'What is Optimize'
metaTitle: 'What is Optimize'
metaDescription: 'Learn about Optimize, a tool that generates insights and recommendations to make your database queries faster.'
tocDepth: 3
toc: true
---

<TopBlock>

[Optimize](https://www.prisma.io/data-platform/optimize) is a tool designed to generate insights, help you debug database queries, and provide recommendations to make your queries faster.

Key features include:

- Generating insights about your database queries
- Identifying errors to help debug your database queries
- Providing recommendations to improve query performance

Optimize aims to help developers of all skill levels write efficient database queries, reducing database load and making applications more responsive.

</TopBlock>
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
74 changes: 74 additions & 0 deletions content/700-optimize/200-getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
title: 'Getting started'
metaTitle: 'Getting started with Prisma Optimize'
metaDescription: 'Learn how to get up and running with Prisma Optimize.'
tocDepth: 3
toc: true
---

## Prerequisites

To get started with Optimize, you will need the following:

- A [Prisma Data Platform workspace](https://console.prisma.io).
- A project that uses [Prisma Client](/orm/prisma-client) `5.16.1` or higher (We always recommend using the latest version of Prisma).
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
- A PostgreSQL, MySQL/MariaDB, PlanetScale, CockroachDB, or MongoDB database.
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved

## 1. Enable Optimize

Login to your [Prisma Data Platform account](https://console.prisma.io) and then navigate to the [ Optimize dashboard](https://optimize.prisma.io).

<Admonition>

You should use Optimize in your development or staging environment.
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved

</Admonition>

## 2. Add Optimize to your application

### 2.1. Update your `schema.prisma` file

In your Prisma schema's `generator` block add the `tracing` preview feature:
```prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["tracing"]
}
```

Then generate a Prisma Client using:
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
```terminal
npx prisma generate
```

### 2.2. Install the Optimize Prisma Client extension

Install the latest version of Prisma Client and Optimize Prisma Client extension:
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved

```terminal
npm install @prisma/client@latest @prisma/extension-optimize
```

### 2.3. Extend your Prisma Client instance with the Optimize extension

Add the following to extend your existing Prisma Client instance with the Optimize extension:

```ts
import { PrismaClient } from '@prisma/client'
import { withOptimize } from '@prisma/extension-optimize'

const prisma = new PrismaClient().$extends(withOptimize())
```

### 2.4. Use Prisma Optimize to generate insights

Create a new recording in your Prisma Optimize dashboard to receive insights on your database queries. Follow these steps:
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
1. Locate and click the **Start recording** button and then run your script.
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
2. Once you see query insights are generated for the desired queries or your script completes execution, locate and click the **Stop recording** button. You can then click on the individual queries to see more details.
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
3. Navigate to the **Recommendations** tab to see if any improvements have been suggested by Optimize to improve query performance.

You can also try out the [step-by-step example](https://github.com/prisma/prisma-examples/optimize/starter) to learn more.
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved

## Need help?

Reach out to us in the `#help-and-questions` channel on our [Discord](https://pris.ly/discord), or connect with our community to see how others are using Pulse.
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
49 changes: 49 additions & 0 deletions content/700-optimize/300-recording.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: 'Recording'
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
metaTitle: 'Optimize: Recording'
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved
metaDescription: "Learn about using Optimize's recording feature."
tocDepth: 3
toc: true
---

<TopBlock>

The Recordings feature is designed to help developers debug and isolate different sets of queries into distinct sessions, known as recordings. This targeted approach enables precise performance analysis and optimization by preventing the mixing of queries from different applications or test rounds, leading to clearer insights and more effective debugging.

</TopBlock>

## Managing a recording session

You can manually start and stop recording sessions via the [Optimize dashboard](https://optimize.prisma.io) by clicking the **Start Recording** and **Stop Recording** buttons.

:::warning

A recording will automatically stop if the 10k query limit is reached or if the Prisma schema of the app is changed.

:::

A recording session can be deleted when no longer needed.

## Identifying a recording session

You can rename and tag your recording sessions for easy identification and context. Click on the generated default name of the recording session and type the desired name.

## Data captured in a recording session

Each recording session captures insights about queries executed in your app, including:
- All executed queries during the session.
- **Raw Query**: The raw query generated and sent to the database by Prisma ORM.
- **Count**: The number of times a query pattern was executed.
- [Query performance metrics](/optimize/performance-metrics).
- Errors encountered during query execution.
ankur-arch marked this conversation as resolved.
Show resolved Hide resolved

Each recording can have a maximum of 10k queries. There are no limits on the storage retention period.

## Recommendations from a recording session

When a recording session ends, Optimize generates recommendations such as:
- [Excessive number of rows returned](/optimize/recommendations#excessive-number-of-rows-returned)
- [Full table scans caused by LIKE operations](/optimize/recommendations#full-table-scans-caused-by-like-operations)
- [Queries on unindexed columns](/optimize/recommendations#queries-on-unindexed-columns)

Learn more about the recommendations generated by Optimize [here](/optimize/recommendations).
Loading
Loading