perf: add limit: 1 and pagination: false to various payload queries (#11319)

`payload.find` queries can be made faster by specifying `limit: 1` and `pagination: false` when only the first document is needed. This PR applies those options to various queries to improve performance.
This commit is contained in:
Alessio Gravili
2025-02-21 11:09:40 -07:00
committed by GitHub
parent 6ff380ce59
commit 0058f82d87
6 changed files with 13 additions and 0 deletions

View File

@@ -54,6 +54,8 @@ async function autoLogin({
await payload.find({
collection: collection.config.slug,
depth: isGraphQL ? 0 : collection.config.auth.depth,
limit: 1,
pagination: false,
where,
})
).docs[0]

View File

@@ -52,6 +52,7 @@ export async function getGlobalViewRedirect({
depth: 0,
limit: 1,
overrideAccess: false,
pagination: false,
user,
where: {
[tenantFieldName]: {

View File

@@ -12,6 +12,8 @@ export const deleteFromSearch: DeleteFromSearch = async ({
const searchDocQuery = await payload.find({
collection: searchSlug,
depth: 0,
limit: 1,
pagination: false,
req,
where: {
doc: {

View File

@@ -149,7 +149,9 @@ export const syncDocAsSearchIndex = async ({
} = await payload.find({
collection,
draft: false,
limit: 1,
locale: syncLocale,
pagination: false,
req,
where: {
and: [

View File

@@ -54,6 +54,8 @@ export const handleCreatedOrUpdated: HandleCreatedOrUpdated = async (args) => {
// First, search for an existing document in Payload
const payloadQuery = await payload.find({
collection: collectionSlug,
limit: 1,
pagination: false,
where: {
stripeID: {
equals: stripeID,
@@ -95,6 +97,8 @@ export const handleCreatedOrUpdated: HandleCreatedOrUpdated = async (args) => {
if (stripeDoc?.email) {
const authQuery = await payload.find({
collection: collectionSlug,
limit: 1,
pagination: false,
where: {
email: {
equals: stripeDoc.email,

View File

@@ -40,6 +40,8 @@ export const handleDeleted: HandleDeleted = async (args) => {
try {
const payloadQuery = await payload.find({
collection: collectionSlug,
limit: 1,
pagination: false,
where: {
stripeID: {
equals: stripeID,