Skip to content

perf(graphql): skip count query for join field using simple pagination #12223

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

Merged
merged 2 commits into from
Apr 29, 2025
Merged
Changes from all commits
Commits
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
17 changes: 15 additions & 2 deletions packages/graphql/src/schema/fieldToSchemaMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,19 +393,32 @@ export const fieldToSchemaMap: FieldToSchemaMap = {
throw new Error('GraphQL with array of join.field.collection is not implemented')
}

return await req.payload.find({
const { docs } = await req.payload.find({
collection,
depth: 0,
draft,
fallbackLocale: req.fallbackLocale,
limit,
// Fetch one extra document to determine if there are more documents beyond the requested limit (used for hasNextPage calculation).
limit: typeof limit === 'number' && limit > 0 ? limit + 1 : 0,
locale: req.locale,
overrideAccess: false,
page,
pagination: false,
req,
sort,
where: fullWhere,
})

let shouldSlice = false

if (typeof limit === 'number' && limit !== 0 && limit < docs.length) {
shouldSlice = true
}

return {
docs: shouldSlice ? docs.slice(0, -1) : docs,
hasNextPage: limit === 0 ? false : limit < docs.length,
}
},
}

Expand Down
Loading