Skip to content

Commit ea15f00

Browse files
authored
chore: deprecate skip parameter from db-adapters (#15183)
`skip` is an internal API. It is used only by the database adapters and is not publicly exposed through the local API, only when accessing the database directly. It does exactly the same thing as `page`, but with different semantics. In this PR I am deprecating it because it adds nothing but complexity. It is used only once in the entire repository and conflicts with the `page` parameter.
1 parent 13e6035 commit ea15f00

7 files changed

Lines changed: 15 additions & 10 deletions

File tree

packages/db-mongodb/src/findGlobalVersions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export const findGlobalVersions: FindGlobalVersions = async function findGlobalV
2222
pagination,
2323
req,
2424
select,
25-
skip,
2625
sort: sortArg,
2726
where = {},
2827
},
@@ -58,6 +57,8 @@ export const findGlobalVersions: FindGlobalVersions = async function findGlobalV
5857
})
5958

6059
const session = await getSession(this, req)
60+
// Calculate skip from page for cases where pagination is disabled but offset is still needed
61+
const skip = typeof page === 'number' && page > 1 ? (page - 1) * (limit || 0) : undefined
6162
const options: QueryOptions = {
6263
limit,
6364
session,

packages/db-mongodb/src/findVersions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export const findVersions: FindVersions = async function findVersions(
2222
pagination,
2323
req = {},
2424
select,
25-
skip,
2625
sort: sortArg,
2726
where = {},
2827
},
@@ -62,6 +61,8 @@ export const findVersions: FindVersions = async function findVersions(
6261
})
6362

6463
const session = await getSession(this, req)
64+
// Calculate skip from page for cases where pagination is disabled but offset is still needed
65+
const skip = typeof page === 'number' && page > 1 ? (page - 1) * (limit || 0) : undefined
6566
const options: QueryOptions = {
6667
limit,
6768
session,

packages/drizzle/src/find/findMany.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export const findMany = async function find({
3131
pagination,
3232
req,
3333
select,
34-
skip,
3534
sort,
3635
tableName,
3736
versions,
@@ -43,7 +42,7 @@ export const findMany = async function find({
4342
let hasPrevPage: boolean
4443
let hasNextPage: boolean
4544
let pagingCounter: number
46-
const offset = skip || (page - 1) * limit
45+
const offset = (page - 1) * limit
4746

4847
if (limit === 0) {
4948
pagination = false

packages/drizzle/src/findGlobalVersions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { findMany } from './find/findMany.js'
99

1010
export const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(
1111
this: DrizzleAdapter,
12-
{ global, limit, locale, page, pagination, req, select, skip, sort: sortArg, where },
12+
{ global, limit, locale, page, pagination, req, select, sort: sortArg, where },
1313
) {
1414
const globalConfig: SanitizedGlobalConfig = this.payload.globals.config.find(
1515
({ slug }) => slug === global,
@@ -31,7 +31,6 @@ export const findGlobalVersions: FindGlobalVersions = async function findGlobalV
3131
pagination,
3232
req,
3333
select,
34-
skip,
3534
sort,
3635
tableName,
3736
where,

packages/drizzle/src/findVersions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { findMany } from './find/findMany.js'
99

1010
export const findVersions: FindVersions = async function findVersions(
1111
this: DrizzleAdapter,
12-
{ collection, limit, locale, page, pagination, req, select, skip, sort: sortArg, where },
12+
{ collection, limit, locale, page, pagination, req, select, sort: sortArg, where },
1313
) {
1414
const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config
1515
const sort = sortArg !== undefined && sortArg !== null ? sortArg : collectionConfig.defaultSort
@@ -30,7 +30,6 @@ export const findVersions: FindVersions = async function findVersions(
3030
pagination,
3131
req,
3232
select,
33-
skip,
3433
sort,
3534
tableName,
3635
where,

packages/payload/src/database/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ export type FindArgs = {
242242
projection?: Record<string, unknown>
243243
req?: Partial<PayloadRequest>
244244
select?: SelectType
245+
/**
246+
* @deprecated This parameter is going to be removed in the next major version. Use page instead.
247+
*/
245248
skip?: number
246249
sort?: Sort
247250
versions?: boolean
@@ -277,6 +280,9 @@ type BaseVersionArgs = {
277280
pagination?: boolean
278281
req?: Partial<PayloadRequest>
279282
select?: SelectType
283+
/**
284+
* @deprecated This parameter is going to be removed in the next major version. Use page instead.
285+
*/
280286
skip?: number
281287
sort?: Sort
282288
versions?: boolean

packages/payload/src/versions/enforceMaxVersions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export const enforceMaxVersions = async ({
3535
const query = await payload.db.findVersions({
3636
collection: collection.slug,
3737
limit: 1,
38+
page: max + 1,
3839
pagination: false,
3940
req,
40-
skip: max,
4141
sort: '-updatedAt',
4242
where,
4343
})
@@ -47,9 +47,9 @@ export const enforceMaxVersions = async ({
4747
const query = await payload.db.findGlobalVersions({
4848
global: globalConfig.slug,
4949
limit: 1,
50+
page: max + 1,
5051
pagination: false,
5152
req,
52-
skip: max,
5353
sort: '-updatedAt',
5454
where,
5555
})

0 commit comments

Comments
 (0)