Skip to content

Commit 14353fe

Browse files
committed
wip: gantt walks to its row ceiling in steps under a host's maximum page size
1 parent 9348f02 commit 14353fe

6 files changed

Lines changed: 211 additions & 34 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/plugin-gantt': patch
3+
'@object-ui/core': patch
4+
---
5+
6+
fix(gantt): a gantt opens on a host that sets a maximum page size, instead of showing the refusal
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
The gantt read its whole filtered result set, up to its 10,000-row ceiling, as ONE read of 10,001 rows (the ceiling plus the probe row that makes a cut detectable). A host that sets a maximum page size (`OS_DATA_MAX_PAGE_SIZE`; the hosted plane sets 5,000) refuses any read over it before running the query, so on every such host the gantt drew "Query parameter 'top' asks for 10001 rows; this deployment's maximum page size is 5000…" in place of the chart, for an empty object as much as a full one.
12+
13+
The gantt now walks to its ceiling in steps of at most 2,001 rows, the one read the calendar, map, tree and timesheet already send: `$skip` moves by the rows that came back, and the walk stops at the first short answer or one row past the ceiling. The ceiling, the footnote that names a cut, and the rule that an authored `pagination.pageSize` or `limit` never reaches the read are unchanged; a result set that fits one step is still one read.

‎ui/packages/core/src/utils/non-grid-row-ceiling.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ export const NON_GRID_ROW_CEILING = 2000;
135135
* value. Past it (10,500 rows) the probe row cuts at 10,000 and
136136
* `NonGridRowCeilingNote` shows, as below the shared ceiling.
137137
*
138+
* ⛔ A STOP CONDITION, NOT A REQUEST SIZE. The gantt reaches this ceiling in
139+
* steps no larger than the shared ceiling's one read (`fetchGanttRows`,
140+
* `@object-ui/plugin-gantt`). Sent as one `$top` of 10,001 it was refused
141+
* outright by any host whose maximum page size is smaller
142+
* (`OS_DATA_MAX_PAGE_SIZE`; the hosted plane sets 5,000), on an empty object
143+
* as on a full one, and the refusal drew in place of the chart.
144+
*
138145
* ⚠️ As with the table above: SHARED-BOX seconds and a reading taken once,
139146
* when objectstack#32421 landed; nothing re-derives it. The DOM counts are
140147
* the environment-independent half.
@@ -173,8 +180,11 @@ export type NonGridRowCeiling = typeof NON_GRID_ROW_CEILING | typeof GANTT_ROW_C
173180
* A fresh object per call, so a caller that mutates the query it built cannot
174181
* change what the next caller sends.
175182
*
176-
* `ceiling` defaults to the shared {@link NON_GRID_ROW_CEILING}; only the
177-
* gantt passes {@link GANTT_ROW_CEILING}. A caller passes the SAME ceiling to
183+
* `ceiling` defaults to the shared {@link NON_GRID_ROW_CEILING}, and every
184+
* view that spreads this query passes no other: ⛔ it is ONE read, and
185+
* {@link GANTT_ROW_CEILING} plus its probe row (10,001) is over the maximum
186+
* page size a host may set, so the gantt walks to its ceiling in steps instead
187+
* (see that constant). A caller passes the SAME ceiling to
178188
* {@link applyNonGridRowCeiling}, or the probe row is sliced at the wrong
179189
* place.
180190
*/

‎ui/packages/plugin-gantt/src/ObjectGantt.elementDataSource.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { render, waitFor } from '@testing-library/react';
3131
import React from 'react';
3232
import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
3333
import { I18nProvider } from '@object-ui/i18n';
34-
import { GANTT_ROW_CEILING, nonGridRowCeilingQuery } from '@object-ui/core';
34+
import { GANTT_FETCH_STEP } from './ganttRowWalk';
3535

3636
vi.mock('sonner', () => ({ toast: { error: vi.fn() } }));
3737

@@ -164,7 +164,7 @@ describe('object-gantt — dataSource: { object, view } (objectstack#7121)', ()
164164
// Not an oversight — `limit` is unmapped because there is no read site. The
165165
// assertion is here so a future mapping addition has to be deliberate.
166166
expect(params.$top).not.toBe(3);
167-
expect(params.$top).toBe(nonGridRowCeilingQuery(GANTT_ROW_CEILING).$top);
167+
expect(params.$top).toBe(GANTT_FETCH_STEP);
168168
expect(params.options).toBeUndefined();
169169
});
170170

‎ui/packages/plugin-gantt/src/ObjectGantt.harness.test.tsx‎

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { I18nProvider } from '@object-ui/i18n';
5151
import type { DataSource, DeclaredNode, ObjectGanttBlockNode } from '@object-ui/types';
5252
import { safeValidateSchema } from '@object-ui/types/zod';
5353
import { ObjectGantt } from './ObjectGantt';
54+
import { GANTT_FETCH_STEP } from './ganttRowWalk';
5455
// Module scope, not a hook: this import IS the registration (AGENTS.md
5556
// test-discipline section).
5657
import './index';
@@ -322,14 +323,25 @@ describe('ObjectGantt.rowCeiling-7210', () => {
322323

323324
let calls: Array<Record<string, any>> = [];
324325

325-
/** An adapter that HONOURS `$top`, the way a real one does. */
326-
function makeDataSource(storeSize: number) {
326+
/**
327+
* An adapter that HONOURS `$top` and `$skip`, the way a real one does. With
328+
* `maxPageSize` it also refuses a `$top` over it, before reading anything,
329+
* the way a host with `OS_DATA_MAX_PAGE_SIZE` set does (hosted: 5,000).
330+
*/
331+
function makeDataSource(storeSize: number, maxPageSize?: number) {
327332
const store = makeRows(storeSize);
328333
return {
329334
find: vi.fn(async (_resource: string, params: any) => {
330335
calls.push({ ...(params ?? {}) });
331336
const top = typeof params?.$top === 'number' ? params.$top : store.length;
332-
return { data: store.slice(0, top), total: store.length };
337+
if (maxPageSize !== undefined && top > maxPageSize) {
338+
throw new Error(
339+
`Query parameter 'top' asks for ${top} rows; this deployment's maximum page size is ${maxPageSize}. `
340+
+ `The query was not run. Ask for at most ${maxPageSize} rows and page with offset.`,
341+
);
342+
}
343+
const skip = typeof params?.$skip === 'number' ? params.$skip : 0;
344+
return { data: store.slice(skip, skip + top), total: store.length };
333345
}),
334346
findOne: vi.fn(),
335347
create: vi.fn(),
@@ -374,12 +386,17 @@ describe('ObjectGantt.rowCeiling-7210', () => {
374386
),
375387
);
376388

377-
// The fetch asked for one probe row past the ceiling — that is what makes
378-
// the cut a fact about the rows in hand rather than a guess.
379-
expect(calls.length).toBeGreaterThan(0);
380-
for (const params of calls) {
381-
expect(params.$top).toBe(nonGridRowCeilingQuery(GANTT_ROW_CEILING).$top);
382-
}
389+
// The walk read one probe row past the ceiling — that is what makes the
390+
// cut a fact about the rows in hand rather than a guess — and asked no
391+
// single read for more than one step (objectstack: a hosted maximum page
392+
// size refuses a `$top` of 10,001).
393+
const wanted = nonGridRowCeilingQuery(GANTT_ROW_CEILING).$top;
394+
const tops = calls.map((params) => params.$top);
395+
expect(tops.reduce((sum, top) => sum + top, 0)).toBe(wanted);
396+
for (const top of tops) expect(top).toBeLessThanOrEqual(GANTT_FETCH_STEP);
397+
expect(calls.map((params) => params.$skip ?? 0)).toEqual(
398+
tops.map((_, i) => tops.slice(0, i).reduce((sum, top) => sum + top, 0)),
399+
);
383400

384401
// ⭐ The half the ruling cares about: the truncation is NOT silent.
385402
const note = await screen.findByRole('note');
@@ -410,11 +427,60 @@ describe('ObjectGantt.rowCeiling-7210', () => {
410427
);
411428
expect(calls.length).toBeGreaterThan(0);
412429
for (const params of calls) {
413-
expect(params.$top).toBe(GANTT_ROW_CEILING + 1);
430+
expect(params.$top).toBe(GANTT_FETCH_STEP);
414431
}
415432
expect(screen.queryByRole('note')).toBeNull();
416433
});
417434

435+
/**
436+
* objectstack — the hosted refusal. A host with a maximum page size (the
437+
* hosted plane sets `OS_DATA_MAX_PAGE_SIZE` to 5,000) refuses a `$top`
438+
* over it before running the query, so a single read of the ceiling plus
439+
* its probe row (10,001) put the refusal in place of the chart, on an
440+
* EMPTY object as on a full one.
441+
*
442+
* REVERSE VERIFICATION: sending `...nonGridRowCeilingQuery(GANTT_ROW_CEILING)`
443+
* as one read again turns all three of these red at the drawn count, with
444+
* the refusal on screen.
445+
*/
446+
describe('a host with a maximum page size of 5,000', () => {
447+
const HOSTED_MAX_PAGE_SIZE = 5000;
448+
449+
it('draws an empty object instead of the refusal', async () => {
450+
render(<ObjectGantt schema={schema} dataSource={makeDataSource(0, HOSTED_MAX_PAGE_SIZE)} />);
451+
452+
await waitFor(() =>
453+
expect(screen.getByTestId('gantt-view').getAttribute('data-task-count')).toBe('0'),
454+
);
455+
expect(screen.queryByText(/maximum page size/)).toBeNull();
456+
expect(calls).toHaveLength(1);
457+
});
458+
459+
it('draws a set larger than one host page, every row', async () => {
460+
const rows = HOSTED_MAX_PAGE_SIZE + 1234;
461+
render(<ObjectGantt schema={schema} dataSource={makeDataSource(rows, HOSTED_MAX_PAGE_SIZE)} />);
462+
463+
await waitFor(() =>
464+
expect(screen.getByTestId('gantt-view').getAttribute('data-task-count')).toBe(String(rows)),
465+
);
466+
expect(screen.queryByRole('note')).toBeNull();
467+
for (const params of calls) expect(params.$top).toBeLessThanOrEqual(HOSTED_MAX_PAGE_SIZE);
468+
});
469+
470+
it('past the gantt ceiling: draws the ceiling and still says so', async () => {
471+
render(<ObjectGantt schema={schema} dataSource={makeDataSource(TOTAL_ROWS, HOSTED_MAX_PAGE_SIZE)} />);
472+
473+
await waitFor(() =>
474+
expect(screen.getByTestId('gantt-view').getAttribute('data-task-count')).toBe(
475+
String(GANTT_ROW_CEILING),
476+
),
477+
);
478+
const note = await screen.findByRole('note');
479+
expect(note.textContent).toContain(String(GANTT_ROW_CEILING));
480+
expect(note.textContent).toContain(String(TOTAL_ROWS));
481+
});
482+
});
483+
418484
/**
419485
* Ruling B keeps ruling a′'s "not authorable": an authored
420486
* `pagination.pageSize` (or `limit`) does not reach the gantt's query in
@@ -432,7 +498,7 @@ describe('ObjectGantt.rowCeiling-7210', () => {
432498
expect(screen.getByTestId('gantt-view').getAttribute('data-task-count')).toBe('4999'),
433499
);
434500
for (const params of calls) {
435-
expect(params.$top).toBe(GANTT_ROW_CEILING + 1);
501+
expect(params.$top).toBe(GANTT_FETCH_STEP);
436502
}
437503
expect(screen.queryByRole('note')).toBeNull();
438504
unmount();
@@ -641,10 +707,11 @@ describe('ObjectGantt.hostDataProp-7210', () => {
641707
await waitFor(() => expect(calls.length).toBeGreaterThan(0));
642708

643709
for (const params of calls) {
644-
// Not `pagination.pageSize` (2), and not absent either: the platform
645-
// ceiling, one probe row wide so the cut is detectable.
710+
// Not `pagination.pageSize` (2), and not absent either: the walk's
711+
// first step toward the platform ceiling. Five rows answer it short,
712+
// so it is the only read.
646713
expect(params.$top).not.toBe(2);
647-
expect(params.$top).toBe(nonGridRowCeilingQuery(GANTT_ROW_CEILING).$top);
714+
expect(params.$top).toBe(GANTT_FETCH_STEP);
648715
expect(params.$skip).toBeUndefined();
649716
}
650717
});

‎ui/packages/plugin-gantt/src/ObjectGantt.tsx‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ import {
7676
resolveAffordance,
7777
type SchemaLike,
7878
applyNonGridRowCeiling,
79-
nonGridRowCeilingQuery,
8079
GANTT_ROW_CEILING,
8180
type NonGridCeilingResult,
8281
isRealCalendarDate,
@@ -97,6 +96,7 @@ import {
9796
} from '@object-ui/fields';
9897
import { GanttView, type GanttTask, type GanttDependency, type GanttLinkType, type GanttTaskType } from './GanttView';
9998
import { invertFrom, invertTo, makeTzShift } from './tzShift';
99+
import { fetchGanttRows } from './ganttRowWalk';
100100
import { ResourceWorkload } from './ResourceWorkload';
101101
import { QuickFilterBar, type QuickFilterField, type QuickFilterOption } from './QuickFilterBar';
102102
import type { WorkingCalendar } from './scheduling';
@@ -1070,22 +1070,27 @@ export const ObjectGantt: React.FC<ObjectGanttProps> = ({
10701070
const expand = !perms?.isLoaded || !resource
10711071
? expandable
10721072
: expandable.filter((f) => perms.checkField(resource, f, 'read'));
1073-
const result = await adapter.find(resource, {
1073+
// The gantt's own ceiling, `GANTT_ROW_CEILING` (objectstack#32421,
1074+
// ruling B), not the shared `NON_GRID_ROW_CEILING` the
1075+
// non-virtualised tree prices (objectui#7210, ruling a′). The gantt
1076+
// still fetches the whole FILTERED result set — a truthful
1077+
// `min(start) → max(end)` range and the group rollups need all of it,
1078+
// which is why paging this at `pagination.pageSize` was rejected — but
1079+
// "the whole result set" stops at a number instead of at whatever the
1080+
// table happens to hold. The walk reads one probe row past the ceiling,
1081+
// which is what makes the cut DETECTABLE; `applyNonGridRowCeiling`
1082+
// slices it back off at the SAME ceiling. ⛔ Not authorable: an
1083+
// authored `limit` / `pagination.pageSize` still cannot reach this
1084+
// query, and neither does a datasource's `external.rowCap`, by both
1085+
// rulings.
1086+
//
1087+
// ⛔ The ceiling is a stop condition, not a request size: the walk asks
1088+
// in `GANTT_FETCH_STEP` steps, because a host with a maximum page size
1089+
// (hosted: 5,000) refuses one `$top` of 10,001 outright, empty object
1090+
// or not. See `./ganttRowWalk`.
1091+
const result = await fetchGanttRows((params) => adapter.find(resource, params), {
10741092
$filter: queryFilter,
10751093
$orderby: convertSortToQueryParams(schema.sort),
1076-
// The gantt's own ceiling, `GANTT_ROW_CEILING` (objectstack#32421,
1077-
// ruling B), not the shared `NON_GRID_ROW_CEILING` the
1078-
// non-virtualised tree prices (objectui#7210, ruling a′). The gantt
1079-
// still fetches the whole FILTERED result set — a truthful
1080-
// `min(start) → max(end)` range and the group rollups need all of it,
1081-
// which is why paging this at `pagination.pageSize` was rejected — but
1082-
// "the whole result set" stops at a number instead of at whatever the
1083-
// table happens to hold. One probe row past the ceiling is what makes
1084-
// the cut DETECTABLE; `applyNonGridRowCeiling` slices it back off at
1085-
// the SAME ceiling. ⛔ Not authorable: an authored `limit` /
1086-
// `pagination.pageSize` still cannot reach this query, and neither
1087-
// does a datasource's `external.rowCap`, by both rulings.
1088-
...nonGridRowCeilingQuery(GANTT_ROW_CEILING),
10891094
...(expand.length > 0 ? { $expand: expand } : {}),
10901095
// objectui#10250 — the term and its field narrowing, sent together
10911096
// or not at all. See `searchTerm` above.
@@ -1095,7 +1100,7 @@ export const ObjectGantt: React.FC<ObjectGanttProps> = ({
10951100
...(searchFields ? { $searchFields: searchFields } : {}),
10961101
}
10971102
: {}),
1098-
});
1103+
}, isCurrent);
10991104
const capped = applyNonGridRowCeiling(result, GANTT_ROW_CEILING);
11001105
if (isCurrent()) {
11011106
setData(capped.rows);
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import {
10+
extractRecords,
11+
nonGridRowCeilingQuery,
12+
GANTT_ROW_CEILING,
13+
} from '@object-ui/core';
14+
15+
/**
16+
* The most rows ONE gantt read asks for: the shared non-grid ceiling plus its
17+
* probe row (2,001), the same single request the calendar, map, tree and
18+
* timesheet send.
19+
*
20+
* The gantt's own ceiling ({@link GANTT_ROW_CEILING}, 10,000, objectstack#32421
21+
* ruling B) is a stop condition, not a request size. It used to be sent as one
22+
* `$top` of 10,001, and a host that sets a maximum page size refuses any read
23+
* over it before running the query (`OS_DATA_MAX_PAGE_SIZE`, 400
24+
* `MAX_RECORDS_EXCEEDED`, never clamped). The hosted plane sets 5,000, so every
25+
* hosted gantt showed that refusal in place of the chart, an EMPTY one too: the
26+
* refusal is decided by the `$top` asked for, not by the rows the object holds.
27+
*
28+
* So the gantt walks its result set in steps of this size, and asks no single
29+
* read for more than the other non-grid views already ask for. A deployment
30+
* whose maximum page size is below this refuses all five views alike; the
31+
* gantt is no longer the one view that needs a larger page than the rest.
32+
*/
33+
export const GANTT_FETCH_STEP: number = nonGridRowCeilingQuery().$top;
34+
35+
/**
36+
* Read the gantt's filtered result set up to {@link GANTT_ROW_CEILING} plus
37+
* the probe row, in steps of at most {@link GANTT_FETCH_STEP} rows.
38+
*
39+
* `$top` is the step (or the rows still wanted, at the end), `$skip` moves by
40+
* the rows that came back, and the walk stops at the first short answer or one
41+
* row past the ceiling, so `applyNonGridRowCeiling(result, GANTT_ROW_CEILING)`
42+
* still reads truncation from the rows in hand. A platform read that carries
43+
* `limit` or `offset` is a partition of the result set (the drivers append the
44+
* `id` tie-breaker), so the steps neither repeat nor skip a row.
45+
*
46+
* A first answer that already settles it is returned AS IS, envelope and all:
47+
* a short one (the whole set fits one step, the common case) or one longer than
48+
* the step (an adapter that ignores `$top`, which the ceiling then slices).
49+
* Only a walk of several steps is re-wrapped, as `{ data, total? }`, with the
50+
* newest `total` an answer reported.
51+
*
52+
* `isCurrent` is asked after every answer: when a newer reload owns the screen
53+
* the walk stops asking, and its caller discards what it has.
54+
*/
55+
export async function fetchGanttRows(
56+
find: (params: Record<string, unknown>) => Promise<unknown>,
57+
params: Record<string, unknown>,
58+
isCurrent: () => boolean = () => true,
59+
): Promise<unknown> {
60+
const wanted = GANTT_ROW_CEILING + 1;
61+
const firstTop = Math.min(GANTT_FETCH_STEP, wanted);
62+
const first = await find({ ...params, $top: firstTop });
63+
const firstRows = extractRecords(first);
64+
if (firstRows.length !== firstTop || !isCurrent()) return first;
65+
66+
const data: unknown[] = [...firstRows];
67+
let total = reportedTotal(first);
68+
while (data.length < wanted) {
69+
const top = Math.min(GANTT_FETCH_STEP, wanted - data.length);
70+
const result = await find({ ...params, $top: top, $skip: data.length });
71+
const rows = extractRecords(result);
72+
total = reportedTotal(result) ?? total;
73+
data.push(...rows);
74+
if (rows.length < top || !isCurrent()) break;
75+
}
76+
return total !== undefined ? { data, total } : { data };
77+
}
78+
79+
function reportedTotal(result: unknown): number | undefined {
80+
const total = result && typeof result === 'object' ? (result as { total?: unknown }).total : undefined;
81+
return typeof total === 'number' ? total : undefined;
82+
}

0 commit comments

Comments
 (0)