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:
@@ -54,6 +54,8 @@ async function autoLogin({
|
|||||||
await payload.find({
|
await payload.find({
|
||||||
collection: collection.config.slug,
|
collection: collection.config.slug,
|
||||||
depth: isGraphQL ? 0 : collection.config.auth.depth,
|
depth: isGraphQL ? 0 : collection.config.auth.depth,
|
||||||
|
limit: 1,
|
||||||
|
pagination: false,
|
||||||
where,
|
where,
|
||||||
})
|
})
|
||||||
).docs[0]
|
).docs[0]
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ export async function getGlobalViewRedirect({
|
|||||||
depth: 0,
|
depth: 0,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
overrideAccess: false,
|
overrideAccess: false,
|
||||||
|
pagination: false,
|
||||||
user,
|
user,
|
||||||
where: {
|
where: {
|
||||||
[tenantFieldName]: {
|
[tenantFieldName]: {
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ export const deleteFromSearch: DeleteFromSearch = async ({
|
|||||||
const searchDocQuery = await payload.find({
|
const searchDocQuery = await payload.find({
|
||||||
collection: searchSlug,
|
collection: searchSlug,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
|
limit: 1,
|
||||||
|
pagination: false,
|
||||||
req,
|
req,
|
||||||
where: {
|
where: {
|
||||||
doc: {
|
doc: {
|
||||||
|
|||||||
@@ -149,7 +149,9 @@ export const syncDocAsSearchIndex = async ({
|
|||||||
} = await payload.find({
|
} = await payload.find({
|
||||||
collection,
|
collection,
|
||||||
draft: false,
|
draft: false,
|
||||||
|
limit: 1,
|
||||||
locale: syncLocale,
|
locale: syncLocale,
|
||||||
|
pagination: false,
|
||||||
req,
|
req,
|
||||||
where: {
|
where: {
|
||||||
and: [
|
and: [
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ export const handleCreatedOrUpdated: HandleCreatedOrUpdated = async (args) => {
|
|||||||
// First, search for an existing document in Payload
|
// First, search for an existing document in Payload
|
||||||
const payloadQuery = await payload.find({
|
const payloadQuery = await payload.find({
|
||||||
collection: collectionSlug,
|
collection: collectionSlug,
|
||||||
|
limit: 1,
|
||||||
|
pagination: false,
|
||||||
where: {
|
where: {
|
||||||
stripeID: {
|
stripeID: {
|
||||||
equals: stripeID,
|
equals: stripeID,
|
||||||
@@ -95,6 +97,8 @@ export const handleCreatedOrUpdated: HandleCreatedOrUpdated = async (args) => {
|
|||||||
if (stripeDoc?.email) {
|
if (stripeDoc?.email) {
|
||||||
const authQuery = await payload.find({
|
const authQuery = await payload.find({
|
||||||
collection: collectionSlug,
|
collection: collectionSlug,
|
||||||
|
limit: 1,
|
||||||
|
pagination: false,
|
||||||
where: {
|
where: {
|
||||||
email: {
|
email: {
|
||||||
equals: stripeDoc.email,
|
equals: stripeDoc.email,
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ export const handleDeleted: HandleDeleted = async (args) => {
|
|||||||
try {
|
try {
|
||||||
const payloadQuery = await payload.find({
|
const payloadQuery = await payload.find({
|
||||||
collection: collectionSlug,
|
collection: collectionSlug,
|
||||||
|
limit: 1,
|
||||||
|
pagination: false,
|
||||||
where: {
|
where: {
|
||||||
stripeID: {
|
stripeID: {
|
||||||
equals: stripeID,
|
equals: stripeID,
|
||||||
|
|||||||
Reference in New Issue
Block a user