From b0547c1b4329f906a08fc194b882f6d3765fc35f Mon Sep 17 00:00:00 2001 From: Admin Date: Wed, 4 Mar 2026 19:39:19 +0500 Subject: [PATCH] fix(ui): paginate listAll to fetch beyond 500 records from PocketBase The previous implementation sent a single request with perPage=500 and silently dropped any records beyond that. Books with 900+ chapters were truncated to 500 in the chapter list and reader prev/next navigation. Now loops through all pages until totalItems is exhausted. --- ui/src/lib/server/pocketbase.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/ui/src/lib/server/pocketbase.ts b/ui/src/lib/server/pocketbase.ts index 8dab9d8..a73ef2d 100644 --- a/ui/src/lib/server/pocketbase.ts +++ b/ui/src/lib/server/pocketbase.ts @@ -132,13 +132,28 @@ interface PBList { } async function listAll(collection: string, filter = '', sort = ''): Promise { - const params = new URLSearchParams({ perPage: '500' }); + const perPage = 500; + const params = new URLSearchParams({ perPage: String(perPage), page: '1' }); if (filter) params.set('filter', filter); if (sort) params.set('sort', sort); - const data = await pbGet>( + + const first = await pbGet>( `/api/collections/${collection}/records?${params.toString()}` ); - return data.items ?? []; + const items: T[] = first.items ?? []; + const total = first.totalItems ?? 0; + + // Fetch remaining pages if there are more records than the first page holds. + const totalPages = Math.ceil(total / perPage); + for (let page = 2; page <= totalPages; page++) { + params.set('page', String(page)); + const data = await pbGet>( + `/api/collections/${collection}/records?${params.toString()}` + ); + items.push(...(data.items ?? [])); + } + + return items; } async function listN(collection: string, n: number, filter = '', sort = ''): Promise {