perf: use server search for large option lists
This commit is contained in:
1 parent
64b86d2a68
commit
acbe64df00
4 files changed
+67
-34
No files matched your search
@@ -1,19 +0,0 @@
|
||||
import http from './http'
|
||||
|
||||
export async function fetchAllPagedItems<T = any>(
|
||||
url: string,
|
||||
params: Record<string, unknown> = {},
|
||||
pageSize = 100,
|
||||
): Promise<T[]> {
|
||||
const items: T[] = []
|
||||
let page = 1
|
||||
|
||||
for (;;) {
|
||||
const response = await http.get(url, { params: { ...params, page, pageSize } })
|
||||
const batch = (response.data?.items ?? []) as T[]
|
||||
items.push(...batch)
|
||||
const total = Number(response.data?.total ?? items.length)
|
||||
if (batch.length === 0 || items.length >= total) return items
|
||||
page++
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user