Simplify page size logic in user search

This commit is contained in:
Andrew Kingston 2023-10-31 13:01:19 +00:00
parent 99a0c8b08b
commit 68553e85d4
1 changed files with 3 additions and 2 deletions

View File

@ -249,7 +249,8 @@ export const paginatedUsers = async ({
limit, limit,
}: SearchUsersRequest = {}) => { }: SearchUsersRequest = {}) => {
const db = getGlobalDB() const db = getGlobalDB()
const pageLimit = limit ? limit + 1 : PAGE_LIMIT + 1 const pageSize = limit ?? PAGE_LIMIT
const pageLimit = pageSize + 1
// get one extra document, to have the next page // get one extra document, to have the next page
const opts: DatabaseQueryOpts = { const opts: DatabaseQueryOpts = {
include_docs: true, include_docs: true,
@ -276,7 +277,7 @@ export const paginatedUsers = async ({
const response = await db.allDocs(getGlobalUserParams(null, opts)) const response = await db.allDocs(getGlobalUserParams(null, opts))
userList = response.rows.map((row: any) => row.doc) userList = response.rows.map((row: any) => row.doc)
} }
return pagination(userList, limit ?? PAGE_LIMIT, { return pagination(userList, pageSize, {
paginate: true, paginate: true,
property, property,
getKey, getKey,