fix(grid): keep load-all chunking past the per-request row cap
This commit is contained in:
1 parent
b09e1fc707
commit
1a3c1f5275
4 files changed
+150
-4
No files matched your search
@@ -219,6 +219,7 @@ import { dataGridHeaderContentWidth, scrollbarGutterWidth } from "@/lib/dataGrid
|
||||
import {
|
||||
canFetchNextDataGridSegment,
|
||||
canGoNextDataGridPage,
|
||||
dataGridLoadAllNextSegment,
|
||||
dataGridLoadAllSegment,
|
||||
dataGridTotalRowCountLabelKey,
|
||||
dataGridUserFacingPage,
|
||||
@@ -3193,6 +3194,10 @@ let infiniteScrollAllLoaded = false;
|
||||
let infiniteScrollRequestedOffset: number | undefined;
|
||||
let infiniteScrollRequestedLimit: number | undefined;
|
||||
let infiniteScrollLoadAllPending = false;
|
||||
// True while an explicit "load all" run is still appending chunks. The per-request
|
||||
// row cap bounds each request, not the run — the run only stops when the server
|
||||
// runs out of rows, so a table larger than the cap does not silently stop halfway (#10752).
|
||||
let loadAllRowsLoopActive = false;
|
||||
const loadAllRowsActive = ref(false);
|
||||
// Tracks whether the current loading cycle was triggered by a refresh/rollback
|
||||
// (as opposed to a normal paginate). Used to decide whether to auto-redirect
|
||||
@@ -3251,9 +3256,14 @@ watch(
|
||||
currentPage.value = Math.max(1, currentPage.value - 1);
|
||||
lastInfiniteScrollPage = Math.max(0, currentPage.value - 1);
|
||||
loadAllRowsActive.value = false;
|
||||
loadAllRowsLoopActive = false;
|
||||
return;
|
||||
}
|
||||
const appendedRows = props.result.rows.length - requestedOffset;
|
||||
if (loadAllRowsLoopActive) {
|
||||
finishOrContinueLoadAllRun(requestedOffset, requestedLimit);
|
||||
return;
|
||||
}
|
||||
if (props.result.rows.length >= infiniteScrollMaxRows.value || appendedRows < (requestedLimit ?? pageSize.value)) {
|
||||
infiniteScrollAllLoaded = true;
|
||||
}
|
||||
@@ -3653,6 +3663,7 @@ function loadAllRowsAndGoToLast() {
|
||||
|
||||
function startLoadAllRows(segment: { offset: number; limit: number }) {
|
||||
loadAllRowsActive.value = true;
|
||||
loadAllRowsLoopActive = true;
|
||||
infiniteScrollLoadAllPending = true;
|
||||
infiniteScrollLoading.value = true;
|
||||
isInfiniteScrollPaginating.value = true;
|
||||
@@ -3662,6 +3673,30 @@ function startLoadAllRows(segment: { offset: number; limit: number }) {
|
||||
emit("paginate", segment.offset, segment.limit, currentWhereInput(), currentOrderBy(), true);
|
||||
}
|
||||
|
||||
// Continues an explicit "load all" run chunk by chunk until the server runs
|
||||
// out of rows (a chunk returns fewer rows than requested) or an exact known
|
||||
// total has been reached. Returns true when another chunk was dispatched.
|
||||
// The per-request result-row cap bounds each chunk, never the run (#10752).
|
||||
function finishOrContinueLoadAllRun(requestedOffset: number | undefined, requestedLimit: number | undefined): boolean {
|
||||
if (!loadAllRowsLoopActive) return false;
|
||||
const nextSegment = canFetchNextInfiniteScrollSegment.value
|
||||
? dataGridLoadAllNextSegment({
|
||||
loadedRowCount: props.result.rows.length,
|
||||
requestedOffset: requestedOffset ?? props.result.rows.length,
|
||||
requestedLimit: requestedLimit ?? pageSize.value,
|
||||
totalRowCount: totalRowCountIsExact.value ? displayedTotalRowCount.value : undefined,
|
||||
})
|
||||
: null;
|
||||
if (!nextSegment) {
|
||||
loadAllRowsLoopActive = false;
|
||||
infiniteScrollAllLoaded = true;
|
||||
selectAndRevealLastLoadedRow();
|
||||
return false;
|
||||
}
|
||||
startLoadAllRows(nextSegment);
|
||||
return true;
|
||||
}
|
||||
|
||||
function confirmLoadAllRows() {
|
||||
const pending = pendingLoadAllRows.value;
|
||||
if (!pending) return;
|
||||
@@ -3692,6 +3727,7 @@ function changePageSize(size: number) {
|
||||
lastInfiniteScrollPage = 0;
|
||||
infiniteScrollAllLoaded = false;
|
||||
loadAllRowsActive.value = false;
|
||||
loadAllRowsLoopActive = false;
|
||||
infiniteScrollPositions = new WeakMap();
|
||||
resetGridVerticalScroll(true);
|
||||
emit("paginate", 0, normalizedSize, currentWhereInput(), currentOrderBy());
|
||||
@@ -4536,6 +4572,7 @@ function resetInfiniteScrollState() {
|
||||
infiniteScrollLoading.value = false;
|
||||
infiniteScrollLoadAllPending = false;
|
||||
loadAllRowsActive.value = false;
|
||||
loadAllRowsLoopActive = false;
|
||||
infiniteScrollPositions = new WeakMap();
|
||||
resetGridVerticalScroll(true);
|
||||
}
|
||||
@@ -10401,9 +10438,15 @@ watch(
|
||||
preservedDetailsOnNextResult = null;
|
||||
const shouldPreserveTranspose = preserveTransposeOnNextResult.value;
|
||||
preserveTransposeOnNextResult.value = false;
|
||||
const appendRequestedOffset = infiniteScrollRequestedOffset;
|
||||
const appendRequestedLimit = infiniteScrollRequestedLimit;
|
||||
const appendCompletion = dataGridInfiniteScrollAppendCompletion(previousResult, result, {
|
||||
pageSize: pageSize.value,
|
||||
maxRows: infiniteScrollMaxRows.value,
|
||||
// While a "load all" run is active the per-request row cap must not be
|
||||
// read as the end of data — only the requested-vs-appended count and an
|
||||
// exact known total end the run (#10752).
|
||||
...(loadAllRowsLoopActive && appendRequestedLimit ? { loadAll: { requestedLimit: appendRequestedLimit, totalRowCount: totalRowCountIsExact.value ? displayedTotalRowCount.value : undefined } } : {}),
|
||||
});
|
||||
if (appendCompletion) {
|
||||
if (infiniteScrollEnabled.value) {
|
||||
@@ -10417,10 +10460,12 @@ watch(
|
||||
}
|
||||
// The append completion above already reset `infiniteScrollLoading`, so the
|
||||
// post-flush loading watcher cannot observe this append; a "load all" run
|
||||
// must still reveal its last row from here.
|
||||
// must still continue or reveal its last row from here.
|
||||
if (infiniteScrollLoadAllPending) {
|
||||
infiniteScrollLoadAllPending = false;
|
||||
selectAndRevealLastLoadedRow();
|
||||
if (!finishOrContinueLoadAllRun(appendRequestedOffset, appendRequestedLimit)) {
|
||||
selectAndRevealLastLoadedRow();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -10428,6 +10473,7 @@ watch(
|
||||
filterValueSuggestionLoader.reset({ clearCache: true });
|
||||
// A non-append result replaces the whole data set, so a running "load all" is over.
|
||||
loadAllRowsActive.value = false;
|
||||
loadAllRowsLoopActive = false;
|
||||
// The replacement also invalidates the all-loaded marker: a filter change or
|
||||
// page jump swaps in a fresh first page whose remaining segments must be
|
||||
// re-derived instead of being silently skipped.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { dataGridBottomScrollTop, dataGridInfiniteScrollAppendCompletion, didDataGridInfiniteScrollContextChange, isDataGridAtScrollBottom, restoredDataGridScrollLeft } from "@/lib/dataGrid/dataGridInfiniteScroll";
|
||||
import { dataGridLoadAllNextSegment } from "@/lib/dataGrid/dataGridPagination";
|
||||
|
||||
describe("data grid bottom anchoring", () => {
|
||||
it("keeps DOM rows anchored when scrollbar padding increases the scroll height", () => {
|
||||
@@ -81,3 +82,66 @@ describe("data grid infinite-scroll append completion", () => {
|
||||
expect(didDataGridInfiniteScrollContextChange([...context.slice(0, 2), "audit", ...context.slice(3)], context)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("data grid load-all loop completion", () => {
|
||||
// #10752: an explicit "load all" run must not stop at the per-request row
|
||||
// cap. A 260k-row table with the default 100k cap appends 99,900 rows in the
|
||||
// first chunk; the cap-hit must not be reported as "all loaded".
|
||||
it("keeps a cap-sized load-all chunk going when rows remain", () => {
|
||||
const previousRows = Array.from({ length: 100 }, (_, index) => [index + 1]);
|
||||
const rows = [...previousRows, ...Array.from({ length: 99_900 }, (_, index) => [index + 101])];
|
||||
|
||||
const completion = dataGridInfiniteScrollAppendCompletion({ rows: previousRows }, { rows, appended_from_row_count: 100, has_more: undefined }, { pageSize: 100, maxRows: 100_000, loadAll: { requestedLimit: 99_900 } });
|
||||
|
||||
expect(completion).toEqual({ loadedPage: 1000, allLoaded: false });
|
||||
});
|
||||
|
||||
it("ends the load-all run when a chunk returns fewer rows than requested", () => {
|
||||
const previousRows = Array.from({ length: 200_000 }, (_, index) => [index + 1]);
|
||||
const rows = [...previousRows, ...Array.from({ length: 60_000 }, (_, index) => [index + 200_001])];
|
||||
|
||||
const completion = dataGridInfiniteScrollAppendCompletion({ rows: previousRows }, { rows, appended_from_row_count: 200_000, has_more: undefined }, { pageSize: 100, maxRows: 100_000, loadAll: { requestedLimit: 100_000 } });
|
||||
|
||||
expect(completion?.allLoaded).toBe(true);
|
||||
});
|
||||
|
||||
it("ends the load-all run when an exact known total has been reached", () => {
|
||||
const previousRows = Array.from({ length: 250_000 }, (_, index) => [index + 1]);
|
||||
const rows = [...previousRows, ...Array.from({ length: 10_000 }, (_, index) => [index + 250_001])];
|
||||
|
||||
const completion = dataGridInfiniteScrollAppendCompletion({ rows: previousRows }, { rows, appended_from_row_count: 250_000, has_more: undefined }, { pageSize: 100, maxRows: 100_000, loadAll: { requestedLimit: 100_000, totalRowCount: 260_000 } });
|
||||
|
||||
expect(completion?.allLoaded).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps the cap-based completion for ordinary infinite scrolls", () => {
|
||||
const previousRows = Array.from({ length: 100 }, (_, index) => [index + 1]);
|
||||
const rows = [...previousRows, ...Array.from({ length: 99_900 }, (_, index) => [index + 101])];
|
||||
|
||||
const completion = dataGridInfiniteScrollAppendCompletion({ rows: previousRows }, { rows, appended_from_row_count: 100, has_more: undefined }, { pageSize: 100, maxRows: 100_000 });
|
||||
|
||||
expect(completion?.allLoaded).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("dataGridLoadAllNextSegment", () => {
|
||||
it("issues the next uncapped chunk after a full chunk", () => {
|
||||
expect(dataGridLoadAllNextSegment({ loadedRowCount: 100_000, requestedOffset: 100, requestedLimit: 99_900 })).toEqual({ offset: 100_000, limit: 99_900 });
|
||||
});
|
||||
|
||||
it("trims the final chunk to an exact known total", () => {
|
||||
expect(dataGridLoadAllNextSegment({ loadedRowCount: 200_000, requestedOffset: 100_000, requestedLimit: 100_000, totalRowCount: 260_000 })).toEqual({ offset: 200_000, limit: 60_000 });
|
||||
});
|
||||
|
||||
it("returns null when the exact known total has been reached", () => {
|
||||
expect(dataGridLoadAllNextSegment({ loadedRowCount: 260_000, requestedOffset: 200_000, requestedLimit: 100_000, totalRowCount: 260_000 })).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null when the server returned fewer rows than requested", () => {
|
||||
expect(dataGridLoadAllNextSegment({ loadedRowCount: 205_000, requestedOffset: 200_000, requestedLimit: 100_000 })).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null when a chunk appended nothing (loop guard)", () => {
|
||||
expect(dataGridLoadAllNextSegment({ loadedRowCount: 200_000, requestedOffset: 200_000, requestedLimit: 100_000 })).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -47,16 +47,33 @@ export function isDataGridPrefixAppend(previous: DataGridAppendResult | undefine
|
||||
return previous.rows.every((row, index) => row === next.rows[index]);
|
||||
}
|
||||
|
||||
export function dataGridInfiniteScrollAppendCompletion(previous: DataGridAppendResult | undefined, next: DataGridAppendResult, options: { pageSize: number; maxRows: number }): DataGridInfiniteScrollAppendCompletion | undefined {
|
||||
export function dataGridInfiniteScrollAppendCompletion(previous: DataGridAppendResult | undefined, next: DataGridAppendResult, options: { pageSize: number; maxRows: number; loadAll?: { requestedLimit: number; totalRowCount?: number } }): DataGridInfiniteScrollAppendCompletion | undefined {
|
||||
if (!isDataGridPrefixAppend(previous, next)) return undefined;
|
||||
|
||||
const pageSize = Math.max(1, Math.floor(options.pageSize));
|
||||
const maxRows = Math.max(1, Math.floor(options.maxRows));
|
||||
const appendedFromRowCount = next.appended_from_row_count!;
|
||||
const appendedRowCount = next.rows.length - appendedFromRowCount;
|
||||
const requestedRowCount = Math.min(pageSize, Math.max(0, maxRows - appendedFromRowCount));
|
||||
const cursorExhausted = !!previous?.session_id && previous.has_more === true && next.has_more === false;
|
||||
|
||||
// An explicit "load all" run keeps appending past the per-request row cap
|
||||
// (the run promised every remaining row), so the cap must not be read as the
|
||||
// end of data here (#10752). The run is over only when the server returned
|
||||
// fewer rows than requested, appended nothing at all, or an exact known
|
||||
// total has been reached.
|
||||
const loadAll = options.loadAll;
|
||||
if (loadAll) {
|
||||
const requestedLimit = Math.max(1, Math.floor(loadAll.requestedLimit));
|
||||
const totalRowCount = typeof loadAll.totalRowCount === "number" && Number.isFinite(loadAll.totalRowCount) && loadAll.totalRowCount >= 0 ? Math.trunc(loadAll.totalRowCount) : undefined;
|
||||
const exhausted = appendedRowCount < requestedLimit || appendedRowCount <= 0 || (totalRowCount !== undefined && next.rows.length >= totalRowCount);
|
||||
return {
|
||||
loadedPage: Math.max(1, Math.ceil(next.rows.length / pageSize)),
|
||||
allLoaded: exhausted,
|
||||
};
|
||||
}
|
||||
|
||||
const requestedRowCount = Math.min(pageSize, Math.max(0, maxRows - appendedFromRowCount));
|
||||
|
||||
return {
|
||||
loadedPage: Math.max(1, Math.ceil(next.rows.length / pageSize)),
|
||||
allLoaded: next.rows.length >= maxRows || appendedRowCount < requestedRowCount || cursorExhausted,
|
||||
|
||||
@@ -134,3 +134,22 @@ export function dataGridLoadAllSegment(loadedRowCount: number, maxRows: number,
|
||||
if (!canFetchMore || offset >= boundedMaxRows) return null;
|
||||
return { offset, limit: boundedMaxRows - offset };
|
||||
}
|
||||
|
||||
/**
|
||||
* Next chunk of an explicit "load all" run, issued after the previous chunk
|
||||
* completed. The per-request result-row cap bounds each request, not the run:
|
||||
* the button promises every remaining row (the confirm dialog quotes the real
|
||||
* remaining count), so stopping at the cap left tables half-loaded (#10752).
|
||||
* The run ends only when the server returns fewer rows than requested, when a
|
||||
* known total has been reached, or when a chunk appends nothing (loop guard).
|
||||
*/
|
||||
export function dataGridLoadAllNextSegment(options: { loadedRowCount: number; requestedOffset: number; requestedLimit: number; totalRowCount?: number }): DataGridLoadAllSegment | null {
|
||||
const loadedRowCount = Number.isFinite(options.loadedRowCount) ? Math.max(0, Math.trunc(options.loadedRowCount)) : 0;
|
||||
const requestedLimit = Number.isFinite(options.requestedLimit) ? Math.max(0, Math.trunc(options.requestedLimit)) : 0;
|
||||
if (requestedLimit <= 0) return null;
|
||||
const appendedRows = loadedRowCount - Math.max(0, Math.trunc(options.requestedOffset));
|
||||
if (appendedRows < requestedLimit) return null;
|
||||
const totalRowCount = typeof options.totalRowCount === "number" && Number.isFinite(options.totalRowCount) && options.totalRowCount >= 0 ? Math.trunc(options.totalRowCount) : undefined;
|
||||
if (totalRowCount !== undefined && loadedRowCount >= totalRowCount) return null;
|
||||
return { offset: loadedRowCount, limit: totalRowCount !== undefined ? Math.min(requestedLimit, totalRowCount - loadedRowCount) : requestedLimit };
|
||||
}
|
||||
Reference in new issue
Block a user