Skip to content

Commit 0058f82

Browse files
authored
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.
1 parent 6ff380c commit 0058f82

File tree

6 files changed

+13
-0
lines changed

6 files changed

+13
-0
lines changed

packages/payload/src/auth/strategies/jwt.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ async function autoLogin({
5454
await payload.find({
5555
collection: collection.config.slug,
5656
depth: isGraphQL ? 0 : collection.config.auth.depth,
57+
limit: 1,
58+
pagination: false,
5759
where,
5860
})
5961
).docs[0]

packages/plugin-multi-tenant/src/utilities/getGlobalViewRedirect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export async function getGlobalViewRedirect({
5252
depth: 0,
5353
limit: 1,
5454
overrideAccess: false,
55+
pagination: false,
5556
user,
5657
where: {
5758
[tenantFieldName]: {

packages/plugin-search/src/Search/hooks/deleteFromSearch.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export const deleteFromSearch: DeleteFromSearch = async ({
1212
const searchDocQuery = await payload.find({
1313
collection: searchSlug,
1414
depth: 0,
15+
limit: 1,
16+
pagination: false,
1517
req,
1618
where: {
1719
doc: {

packages/plugin-search/src/utilities/syncDocAsSearchIndex.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ export const syncDocAsSearchIndex = async ({
149149
} = await payload.find({
150150
collection,
151151
draft: false,
152+
limit: 1,
152153
locale: syncLocale,
154+
pagination: false,
153155
req,
154156
where: {
155157
and: [

packages/plugin-stripe/src/webhooks/handleCreatedOrUpdated.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export const handleCreatedOrUpdated: HandleCreatedOrUpdated = async (args) => {
5454
// First, search for an existing document in Payload
5555
const payloadQuery = await payload.find({
5656
collection: collectionSlug,
57+
limit: 1,
58+
pagination: false,
5759
where: {
5860
stripeID: {
5961
equals: stripeID,
@@ -95,6 +97,8 @@ export const handleCreatedOrUpdated: HandleCreatedOrUpdated = async (args) => {
9597
if (stripeDoc?.email) {
9698
const authQuery = await payload.find({
9799
collection: collectionSlug,
100+
limit: 1,
101+
pagination: false,
98102
where: {
99103
email: {
100104
equals: stripeDoc.email,

packages/plugin-stripe/src/webhooks/handleDeleted.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const handleDeleted: HandleDeleted = async (args) => {
4040
try {
4141
const payloadQuery = await payload.find({
4242
collection: collectionSlug,
43+
limit: 1,
44+
pagination: false,
4345
where: {
4446
stripeID: {
4547
equals: stripeID,

0 commit comments

Comments
 (0)