feat(es): paginate past 10k documents via pit and search_after

This commit is contained in:
Lan-zk authored and GitHub committed 2026-08-30 03:57:03 +08:00
1 parent 1d71a5fc23
commit 73a7b3f2c7
35 files changed
+1622 -153

No files matched your search

@@ -45,20 +45,3 @@ export function clampDocumentPage(page: number, pageSize: number, paginationTota
// DBX can't know a target index's actual configured value up front, so it clamps requests to the
// out-of-the-box default rather than letting an oversized "rows per page" preference reach the cluster as-is.
export const ELASTICSEARCH_DEFAULT_MAX_RESULT_WINDOW = 10_000;
// Clamps a requested page size against the from+size window still available at a given skip offset,
// regardless of where the requested limit came from (a settings default or an explicit override).
export function clampElasticsearchRequestLimit(skip: number, limit: number): number {
const normalizedSkip = Math.max(0, Math.floor(skip));
const normalizedLimit = Math.max(1, Math.floor(limit));
return Math.min(normalizedLimit, Math.max(0, ELASTICSEARCH_DEFAULT_MAX_RESULT_WINDOW - normalizedSkip));
}
export function documentPageRequestLimit(page: number, pageSize: number, paginationTotal?: number): number {
const normalizedPageSize = Math.max(1, Math.floor(pageSize));
const skip = Math.max(0, Math.floor(page)) * normalizedPageSize;
const cappedPageSize = clampElasticsearchRequestLimit(skip, normalizedPageSize);
if (paginationTotal === undefined) return cappedPageSize;
const remaining = paginationTotal - skip;
return remaining > 0 ? Math.min(cappedPageSize, remaining) : cappedPageSize;
}