Skip to content

Commit 6025eff

Browse files
rjgtavRicardo Tavares
andauthored
perf(graphql): optimized join count when docs are not needed (#14872)
### What? Optimizes the count of a join field when the goal is just to retrieve the count value (i.e. limit: 0). ### Why? Generates 1 database query instead of two when the goal is just to retrieve the count value. ### How? By using payload.count() instead of payload.find() Co-authored-by: Ricardo Tavares <[email protected]>
1 parent 070ded7 commit 6025eff

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/graphql/src/schema/fieldToSchemaMap.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,16 @@ export const fieldToSchemaMap: FieldToSchemaMap = {
444444
throw new Error('GraphQL with array of join.field.collection is not implemented')
445445
}
446446

447+
if (count && limit === 0) {
448+
return await req.payload.count({
449+
collection,
450+
depth: 0,
451+
overrideAccess: false,
452+
req,
453+
where: fullWhere,
454+
})
455+
}
456+
447457
const { docs, totalDocs } = await req.payload.find({
448458
collection,
449459
depth: 0,

0 commit comments

Comments
 (0)