Moving limits and offsets back into pre-query.
This commit is contained in:
parent
73013332ae
commit
278242fb55
1 changed files with 24 additions and 23 deletions
|
@ -590,9 +590,28 @@ class InternalBuilder {
|
||||||
}
|
}
|
||||||
// start building the query
|
// start building the query
|
||||||
let query = this.knexWithAlias(knex, endpoint, tableAliases)
|
let query = this.knexWithAlias(knex, endpoint, tableAliases)
|
||||||
// add a base query over all
|
// handle pagination
|
||||||
|
let foundOffset: number | null = null
|
||||||
|
let foundLimit = limit || BASE_LIMIT
|
||||||
|
if (paginate && paginate.page && paginate.limit) {
|
||||||
|
// @ts-ignore
|
||||||
|
const page = paginate.page <= 1 ? 0 : paginate.page - 1
|
||||||
|
const offset = page * paginate.limit
|
||||||
|
foundLimit = paginate.limit
|
||||||
|
foundOffset = offset
|
||||||
|
} else if (paginate && paginate.offset && paginate.limit) {
|
||||||
|
foundLimit = paginate.limit
|
||||||
|
foundOffset = paginate.offset
|
||||||
|
} else if (paginate && paginate.limit) {
|
||||||
|
foundLimit = paginate.limit
|
||||||
|
}
|
||||||
|
// always add the found limit, unless counting
|
||||||
if (!counting) {
|
if (!counting) {
|
||||||
query = query.limit(BASE_LIMIT)
|
query = query.limit(foundLimit)
|
||||||
|
}
|
||||||
|
// add overall pagination
|
||||||
|
if (!counting && foundOffset) {
|
||||||
|
query = query.offset(foundOffset)
|
||||||
}
|
}
|
||||||
// add filters to the query (where)
|
// add filters to the query (where)
|
||||||
query = this.addFilters(query, filters, json.meta.table, {
|
query = this.addFilters(query, filters, json.meta.table, {
|
||||||
|
@ -623,28 +642,10 @@ class InternalBuilder {
|
||||||
endpoint.schema,
|
endpoint.schema,
|
||||||
tableAliases
|
tableAliases
|
||||||
)
|
)
|
||||||
// handle pagination
|
|
||||||
let foundOffset: number | null = null
|
// add a base query over all
|
||||||
let foundLimit = limit || BASE_LIMIT
|
|
||||||
if (paginate && paginate.page && paginate.limit) {
|
|
||||||
// @ts-ignore
|
|
||||||
const page = paginate.page <= 1 ? 0 : paginate.page - 1
|
|
||||||
const offset = page * paginate.limit
|
|
||||||
foundLimit = paginate.limit
|
|
||||||
foundOffset = offset
|
|
||||||
} else if (paginate && paginate.offset && paginate.limit) {
|
|
||||||
foundLimit = paginate.limit
|
|
||||||
foundOffset = paginate.offset
|
|
||||||
} else if (paginate && paginate.limit) {
|
|
||||||
foundLimit = paginate.limit
|
|
||||||
}
|
|
||||||
// always add the found limit, unless counting
|
|
||||||
if (!counting) {
|
if (!counting) {
|
||||||
query = query.limit(foundLimit)
|
query = query.limit(BASE_LIMIT)
|
||||||
}
|
|
||||||
// add overall pagination
|
|
||||||
if (!counting && foundOffset) {
|
|
||||||
query = query.offset(foundOffset)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.addFilters(query, filters, json.meta.table, {
|
return this.addFilters(query, filters, json.meta.table, {
|
||||||
|
|
Loading…
Reference in a new issue