Compare commits

...

1 Commits

Author SHA1 Message Date
Dan Ribbens
fddeb621ca chore: optimize db adapter calls 2024-02-15 15:00:55 -05:00
10 changed files with 21 additions and 18 deletions

View File

@@ -31,6 +31,7 @@ export const incrementLoginAttempts = async ({
lockUntil: null,
loginAttempts: 1,
},
depth: 0,
req,
})
}
@@ -52,6 +53,7 @@ export const incrementLoginAttempts = async ({
id: doc.id,
collection: collection.slug,
data,
depth: 0,
req,
})
}

View File

@@ -23,6 +23,8 @@ export const registerLocalStrategy = async ({
const existingUser = await payload.find({
collection: collection.slug,
depth: 0,
limit: 1,
pagination: false,
where: {
email: {
equals: doc.email,

View File

@@ -23,6 +23,7 @@ export const resetLoginAttempts = async ({
lockUntil: null,
loginAttempts: 0,
},
depth: 0,
overrideAccess: true,
req,
})

View File

@@ -31,16 +31,14 @@ async function deleteOperation(args: PreferenceRequest): Promise<Document> {
],
}
const result = await payload.delete({
const result = await payload.db.deleteOne({
collection: 'payload-preferences',
depth: 0,
user,
req,
where,
})
// @ts-expect-error // TODO: fix later
if (result.docs.length === 1) {
return result.docs[0]
if (result) {
return result
}
throw new NotFound()
}

View File

@@ -8,6 +8,7 @@ async function findOne(
const {
key,
req: { payload },
req,
user,
} = args
@@ -21,17 +22,11 @@ async function findOne(
],
}
const { docs } = await payload.find({
return await payload.db.findOne({
collection: 'payload-preferences',
depth: 0,
pagination: false,
user,
req,
where,
})
if (docs.length === 0) return null
return docs[0]
}
export default findOne

View File

@@ -65,6 +65,7 @@ const replaceWithDraftIfAvailable = async <T extends TypeWithID>({
global: entity.slug,
limit: 1,
locale,
pagination: false,
req,
sort: '-updatedAt',
where: combineQueries(queryToBuild, versionAccessResult),

View File

@@ -1,8 +1,7 @@
import type { SanitizedCollectionConfig } from '../collections/config/types'
import type { SanitizedGlobalConfig } from '../globals/config/types'
import type { Payload } from '../payload'
import type { PayloadRequest } from '../types'
import type { Where } from '../types'
import type { PayloadRequest, Where } from '../types'
type Args = {
collection?: SanitizedCollectionConfig
@@ -46,6 +45,7 @@ export const enforceMaxVersions = async ({
} else if (global) {
const query = await payload.db.findGlobalVersions({
global: global.slug,
pagination: false,
req,
skip: max,
sort: '-updatedAt',

View File

@@ -26,6 +26,8 @@ export const getLatestCollectionVersion = async <T extends TypeWithID = any>({
if (config.versions?.drafts) {
const { docs } = await payload.db.findVersions<T>({
collection: config.slug,
limit: 1,
pagination: false,
req,
sort: '-updatedAt',
where: { parent: { equals: id } },

View File

@@ -14,11 +14,11 @@ type Args = {
}
export const getLatestGlobalVersion = async ({
slug,
config,
locale,
payload,
req,
slug,
where,
}: Args): Promise<{ global: Document; globalExists: boolean }> => {
let latestVersion
@@ -30,6 +30,7 @@ export const getLatestGlobalVersion = async ({
global: slug,
limit: 1,
locale,
pagination: false,
req,
sort: '-updatedAt',
})
@@ -37,9 +38,9 @@ export const getLatestGlobalVersion = async ({
}
const global = await payload.db.findGlobal({
slug,
locale,
req,
slug,
where,
})
const globalExists = Boolean(global)

View File

@@ -40,6 +40,7 @@ export const saveVersion = async ({
let docs
const findVersionArgs = {
limit: 1,
pagination: false,
req,
sort: '-updatedAt',
}