From a07bdbaf467ccf2a5c3da4dbf31cb2e7309e5a49 Mon Sep 17 00:00:00 2001 From: Nikolas Date: Fri, 3 May 2024 17:15:13 +0200 Subject: [PATCH 1/4] Update 100-query-optimization-performance.mdx (#5975) * Update 100-query-optimization-performance.mdx * Update content/200-orm/200-prisma-client/100-queries/100-query-optimization-performance.mdx --- .../100-queries/100-query-optimization-performance.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/content/200-orm/200-prisma-client/100-queries/100-query-optimization-performance.mdx b/content/200-orm/200-prisma-client/100-queries/100-query-optimization-performance.mdx index 6c5c39a7b5..965f49571c 100644 --- a/content/200-orm/200-prisma-client/100-queries/100-query-optimization-performance.mdx +++ b/content/200-orm/200-prisma-client/100-queries/100-query-optimization-performance.mdx @@ -36,7 +36,11 @@ The n+1 problem occurs when you loop through the results of a query and perform -The Prisma Client dataloader automatically **batches** `findUnique()` queries that ✔ occur in the same tick and ✔ have the same `where` and `include` parameters. +The Prisma Client dataloader automatically _batches_ `findUnique()` queries that occur in the same [tick](https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick#processnexttick) and have the same `where` and `include` parameters if: + +- All criteria of the `where` filter are on scalar fields (unique or non-unique) of the same model you're querying. +- All criteria use the `equal` filter, whether that's via the shorthand or explicit syntax `(where: { field: , field1: { equals: } })`. +- No boolean operators or relation filters are present. Automatic batching of `findUnique()` is particularly useful in a **GraphQL context**. GraphQL runs a separate resolver function for every field, which can make it difficult to optimize a nested query. From 788f8120b6e9fa1930b400071bf57af96534fcc0 Mon Sep 17 00:00:00 2001 From: Oskar Radziewicz <60690037+Goodosky@users.noreply.github.com> Date: Sat, 4 May 2024 20:56:42 +0200 Subject: [PATCH 2/4] Fix incorrect globalThis property name in 400-nextjs-prisma-client-dev-practices.mdx (#5978) --- .../400-nextjs-prisma-client-dev-practices.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/200-orm/800-more/600-help-and-troubleshooting/100-help-articles/400-nextjs-prisma-client-dev-practices.mdx b/content/200-orm/800-more/600-help-and-troubleshooting/100-help-articles/400-nextjs-prisma-client-dev-practices.mdx index 4567d1fbd5..93d4c99266 100644 --- a/content/200-orm/800-more/600-help-and-troubleshooting/100-help-articles/400-nextjs-prisma-client-dev-practices.mdx +++ b/content/200-orm/800-more/600-help-and-troubleshooting/100-help-articles/400-nextjs-prisma-client-dev-practices.mdx @@ -30,7 +30,7 @@ const prismaClientSingleton = () => { } declare const globalThis: { - prisma: ReturnType; + prismaGlobal: ReturnType; } & typeof global; const prisma = globalThis.prismaGlobal ?? prismaClientSingleton() From b6a024dd054064be685e3d2c59dc98dbe0115b05 Mon Sep 17 00:00:00 2001 From: Nikolas Date: Mon, 6 May 2024 12:28:33 +0200 Subject: [PATCH 3/4] Update 50-introspection.mdx (#5982) * Update 50-introspection.mdx * Update content/200-orm/100-prisma-schema/50-introspection.mdx * Update content/200-orm/100-prisma-schema/50-introspection.mdx --- content/200-orm/100-prisma-schema/50-introspection.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/content/200-orm/100-prisma-schema/50-introspection.mdx b/content/200-orm/100-prisma-schema/50-introspection.mdx index 1ebae42b3c..729f68a21e 100644 --- a/content/200-orm/100-prisma-schema/50-introspection.mdx +++ b/content/200-orm/100-prisma-schema/50-introspection.mdx @@ -29,8 +29,7 @@ Here's an overview of its main functions on SQL databases: On MongoDB, the main functions are the following: -- Map _collections_ in the database to [Prisma models](/orm/prisma-schema/data-model/models#defining-models) -- Map _documents_ in the collections to the [fields](/orm/prisma-schema/data-model/models#defining-fields) of Prisma models by _sampling them_ +- Map _collections_ in the database to Prisma models. Because a _collection_ in MongoDB doesn't have a predefined structure, Prisma ORM _samples_ the _documents_ in the collection and derives the model structure accordingly (i.e. it maps the [fields](/orm/prisma-schema/data-model/models#defining-fields) of the _document_ to the fields of the Prisma model). If _embedded types_ are detected in a collection, these will be mapped to composite types in the Prisma schema. - Map _indexes_ in the database to [indexes](/orm/prisma-schema/data-model/models#defining-an-index) in the Prisma schema, if the collection contains at least one document contains a field included in the index You can learn more about how Prisma ORM maps types from the database to the types available in the Prisma schema on the respective docs page for the data source connector: From 6e80e5d2e11b9d49b33893777e73f39ed4855e3e Mon Sep 17 00:00:00 2001 From: Nikolas Date: Mon, 6 May 2024 12:35:16 +0200 Subject: [PATCH 4/4] Update 50-introspection.mdx (#5983) --- content/200-orm/100-prisma-schema/50-introspection.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/200-orm/100-prisma-schema/50-introspection.mdx b/content/200-orm/100-prisma-schema/50-introspection.mdx index 729f68a21e..fea51a3b60 100644 --- a/content/200-orm/100-prisma-schema/50-introspection.mdx +++ b/content/200-orm/100-prisma-schema/50-introspection.mdx @@ -29,7 +29,7 @@ Here's an overview of its main functions on SQL databases: On MongoDB, the main functions are the following: -- Map _collections_ in the database to Prisma models. Because a _collection_ in MongoDB doesn't have a predefined structure, Prisma ORM _samples_ the _documents_ in the collection and derives the model structure accordingly (i.e. it maps the [fields](/orm/prisma-schema/data-model/models#defining-fields) of the _document_ to the fields of the Prisma model). If _embedded types_ are detected in a collection, these will be mapped to composite types in the Prisma schema. +- Map _collections_ in the database to [Prisma models](/orm/prisma-schema/data-model/models#defining-models). Because a _collection_ in MongoDB doesn't have a predefined structure, Prisma ORM _samples_ the _documents_ in the collection and derives the model structure accordingly (i.e. it maps the fields of the _document_ to the [fields](/orm/prisma-schema/data-model/models#defining-fields) of the Prisma model). If _embedded types_ are detected in a collection, these will be mapped to [composite types](/orm/prisma-schema/data-model/models#defining-composite-types) in the Prisma schema. - Map _indexes_ in the database to [indexes](/orm/prisma-schema/data-model/models#defining-an-index) in the Prisma schema, if the collection contains at least one document contains a field included in the index You can learn more about how Prisma ORM maps types from the database to the types available in the Prisma schema on the respective docs page for the data source connector: