Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/gantt-paged-ceiling-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@object-ui/plugin-gantt': patch
'@object-ui/core': patch
---

fix(gantt): a gantt opens on a host that sets a maximum page size, instead of showing the refusal

Clause-②: no
Metadata-protocol: none

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.

The gantt now asks no single read for more than 2,001 rows, the one read the calendar, map, tree and timesheet already send. A result set that fits that read is one read, as before. A larger one is walked from the top in steps of that size under a unique order (the authored sort with `id` appended as the tie-breaker) and kept once per row, so a step can neither repeat nor skip a row; 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.
14 changes: 12 additions & 2 deletions ui/packages/core/src/utils/non-grid-row-ceiling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ export const NON_GRID_ROW_CEILING = 2000;
* value. Past it (10,500 rows) the probe row cuts at 10,000 and
* `NonGridRowCeilingNote` shows, as below the shared ceiling.
*
* ⛔ A STOP CONDITION, NOT A REQUEST SIZE. The gantt reaches this ceiling in
* steps no larger than the shared ceiling's one read (`fetchGanttRows`,
* `@object-ui/plugin-gantt`). Sent as one `$top` of 10,001 it was refused
* outright by any host whose maximum page size is smaller
* (`OS_DATA_MAX_PAGE_SIZE`; the hosted plane sets 5,000), on an empty object
* as on a full one, and the refusal drew in place of the chart.
*
* ⚠️ As with the table above: SHARED-BOX seconds and a reading taken once,
* when objectstack#32421 landed; nothing re-derives it. The DOM counts are
* the environment-independent half.
Expand Down Expand Up @@ -173,8 +180,11 @@ export type NonGridRowCeiling = typeof NON_GRID_ROW_CEILING | typeof GANTT_ROW_C
* A fresh object per call, so a caller that mutates the query it built cannot
* change what the next caller sends.
*
* `ceiling` defaults to the shared {@link NON_GRID_ROW_CEILING}; only the
* gantt passes {@link GANTT_ROW_CEILING}. A caller passes the SAME ceiling to
* `ceiling` defaults to the shared {@link NON_GRID_ROW_CEILING}, and every
* view that spreads this query passes no other: ⛔ it is ONE read, and
* {@link GANTT_ROW_CEILING} plus its probe row (10,001) is over the maximum
* page size a host may set, so the gantt walks to its ceiling in steps instead
* (see that constant). A caller passes the SAME ceiling to
* {@link applyNonGridRowCeiling}, or the probe row is sliced at the wrong
* place.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { render, waitFor } from '@testing-library/react';
import React from 'react';
import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
import { I18nProvider } from '@object-ui/i18n';
import { GANTT_ROW_CEILING, nonGridRowCeilingQuery } from '@object-ui/core';
import { GANTT_FETCH_STEP } from './ganttRowWalk';

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

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

Expand Down
99 changes: 85 additions & 14 deletions ui/packages/plugin-gantt/src/ObjectGantt.harness.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { I18nProvider } from '@object-ui/i18n';
import type { DataSource, DeclaredNode, ObjectGanttBlockNode } from '@object-ui/types';
import { safeValidateSchema } from '@object-ui/types/zod';
import { ObjectGantt } from './ObjectGantt';
import { GANTT_FETCH_STEP } from './ganttRowWalk';
// Module scope, not a hook: this import IS the registration (AGENTS.md
// test-discipline section).
import './index';
Expand Down Expand Up @@ -322,14 +323,25 @@ describe('ObjectGantt.rowCeiling-7210', () => {

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

/** An adapter that HONOURS `$top`, the way a real one does. */
function makeDataSource(storeSize: number) {
/**
* An adapter that HONOURS `$top` and `$skip`, the way a real one does. With
* `maxPageSize` it also refuses a `$top` over it, before reading anything,
* the way a host with `OS_DATA_MAX_PAGE_SIZE` set does (hosted: 5,000).
*/
function makeDataSource(storeSize: number, maxPageSize?: number) {
const store = makeRows(storeSize);
return {
find: vi.fn(async (_resource: string, params: any) => {
calls.push({ ...(params ?? {}) });
const top = typeof params?.$top === 'number' ? params.$top : store.length;
return { data: store.slice(0, top), total: store.length };
if (maxPageSize !== undefined && top > maxPageSize) {
throw new Error(
`Query parameter 'top' asks for ${top} rows; this deployment's maximum page size is ${maxPageSize}. `
+ `The query was not run. Ask for at most ${maxPageSize} rows and page with offset.`,
);
}
const skip = typeof params?.$skip === 'number' ? params.$skip : 0;
return { data: store.slice(skip, skip + top), total: store.length };
}),
findOne: vi.fn(),
create: vi.fn(),
Expand Down Expand Up @@ -374,12 +386,21 @@ describe('ObjectGantt.rowCeiling-7210', () => {
),
);

// The fetch asked for one probe row past the ceiling — that is what makes
// the cut a fact about the rows in hand rather than a guess.
expect(calls.length).toBeGreaterThan(0);
for (const params of calls) {
expect(params.$top).toBe(nonGridRowCeilingQuery(GANTT_ROW_CEILING).$top);
}
// The first read came back full, so the set was walked from the top
// under a unique order. The walk read one probe row past the ceiling —
// that is what makes the cut a fact about the rows in hand rather than a
// guess — and asked no single read for more than one step (a hosted
// maximum page size refuses a `$top` of 10,001).
const wanted = nonGridRowCeilingQuery(GANTT_ROW_CEILING).$top;
expect(calls[0].$top).toBe(GANTT_FETCH_STEP);
const walk = calls.slice(1);
const tops = walk.map((params) => params.$top);
expect(tops.reduce((sum, top) => sum + top, 0)).toBe(wanted);
for (const top of tops) expect(top).toBeLessThanOrEqual(GANTT_FETCH_STEP);
expect(walk.map((params) => params.$skip ?? 0)).toEqual(
tops.map((_, i) => tops.slice(0, i).reduce((sum, top) => sum + top, 0)),
);
for (const params of walk) expect(params.$orderby).toEqual({ id: 'asc' });

// ⭐ The half the ruling cares about: the truncation is NOT silent.
const note = await screen.findByRole('note');
Expand Down Expand Up @@ -410,11 +431,60 @@ describe('ObjectGantt.rowCeiling-7210', () => {
);
expect(calls.length).toBeGreaterThan(0);
for (const params of calls) {
expect(params.$top).toBe(GANTT_ROW_CEILING + 1);
expect(params.$top).toBe(GANTT_FETCH_STEP);
}
expect(screen.queryByRole('note')).toBeNull();
});

/**
* objectstack — the hosted refusal. A host with a maximum page size (the
* hosted plane sets `OS_DATA_MAX_PAGE_SIZE` to 5,000) refuses a `$top`
* over it before running the query, so a single read of the ceiling plus
* its probe row (10,001) put the refusal in place of the chart, on an
* EMPTY object as on a full one.
*
* REVERSE VERIFICATION: sending `...nonGridRowCeilingQuery(GANTT_ROW_CEILING)`
* as one read again turns all three of these red at the drawn count, with
* the refusal on screen.
*/
describe('a host with a maximum page size of 5,000', () => {
const HOSTED_MAX_PAGE_SIZE = 5000;

it('draws an empty object instead of the refusal', async () => {
render(<ObjectGantt schema={schema} dataSource={makeDataSource(0, HOSTED_MAX_PAGE_SIZE)} />);

await waitFor(() =>
expect(screen.getByTestId('gantt-view').getAttribute('data-task-count')).toBe('0'),
);
expect(screen.queryByText(/maximum page size/)).toBeNull();
expect(calls).toHaveLength(1);
});

it('draws a set larger than one host page, every row', async () => {
const rows = HOSTED_MAX_PAGE_SIZE + 1234;
render(<ObjectGantt schema={schema} dataSource={makeDataSource(rows, HOSTED_MAX_PAGE_SIZE)} />);

await waitFor(() =>
expect(screen.getByTestId('gantt-view').getAttribute('data-task-count')).toBe(String(rows)),
);
expect(screen.queryByRole('note')).toBeNull();
for (const params of calls) expect(params.$top).toBeLessThanOrEqual(HOSTED_MAX_PAGE_SIZE);
});

it('past the gantt ceiling: draws the ceiling and still says so', async () => {
render(<ObjectGantt schema={schema} dataSource={makeDataSource(TOTAL_ROWS, HOSTED_MAX_PAGE_SIZE)} />);

await waitFor(() =>
expect(screen.getByTestId('gantt-view').getAttribute('data-task-count')).toBe(
String(GANTT_ROW_CEILING),
),
);
const note = await screen.findByRole('note');
expect(note.textContent).toContain(String(GANTT_ROW_CEILING));
expect(note.textContent).toContain(String(TOTAL_ROWS));
});
});

/**
* Ruling B keeps ruling a′'s "not authorable": an authored
* `pagination.pageSize` (or `limit`) does not reach the gantt's query in
Expand All @@ -432,7 +502,7 @@ describe('ObjectGantt.rowCeiling-7210', () => {
expect(screen.getByTestId('gantt-view').getAttribute('data-task-count')).toBe('4999'),
);
for (const params of calls) {
expect(params.$top).toBe(GANTT_ROW_CEILING + 1);
expect(params.$top).toBe(GANTT_FETCH_STEP);
}
expect(screen.queryByRole('note')).toBeNull();
unmount();
Expand Down Expand Up @@ -641,10 +711,11 @@ describe('ObjectGantt.hostDataProp-7210', () => {
await waitFor(() => expect(calls.length).toBeGreaterThan(0));

for (const params of calls) {
// Not `pagination.pageSize` (2), and not absent either: the platform
// ceiling, one probe row wide so the cut is detectable.
// Not `pagination.pageSize` (2), and not absent either: the walk's
// first step toward the platform ceiling. Five rows answer it short,
// so it is the only read.
expect(params.$top).not.toBe(2);
expect(params.$top).toBe(nonGridRowCeilingQuery(GANTT_ROW_CEILING).$top);
expect(params.$top).toBe(GANTT_FETCH_STEP);
expect(params.$skip).toBeUndefined();
}
});
Expand Down
37 changes: 21 additions & 16 deletions ui/packages/plugin-gantt/src/ObjectGantt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ import {
resolveAffordance,
type SchemaLike,
applyNonGridRowCeiling,
nonGridRowCeilingQuery,
GANTT_ROW_CEILING,
type NonGridCeilingResult,
isRealCalendarDate,
Expand All @@ -97,6 +96,7 @@ import {
} from '@object-ui/fields';
import { GanttView, type GanttTask, type GanttDependency, type GanttLinkType, type GanttTaskType } from './GanttView';
import { invertFrom, invertTo, makeTzShift } from './tzShift';
import { fetchGanttRows } from './ganttRowWalk';
import { ResourceWorkload } from './ResourceWorkload';
import { QuickFilterBar, type QuickFilterField, type QuickFilterOption } from './QuickFilterBar';
import type { WorkingCalendar } from './scheduling';
Expand Down Expand Up @@ -1070,22 +1070,27 @@ export const ObjectGantt: React.FC<ObjectGanttProps> = ({
const expand = !perms?.isLoaded || !resource
? expandable
: expandable.filter((f) => perms.checkField(resource, f, 'read'));
const result = await adapter.find(resource, {
// The gantt's own ceiling, `GANTT_ROW_CEILING` (objectstack#32421,
// ruling B), not the shared `NON_GRID_ROW_CEILING` the
// non-virtualised tree prices (objectui#7210, ruling a′). The gantt
// still fetches the whole FILTERED result set — a truthful
// `min(start) → max(end)` range and the group rollups need all of it,
// which is why paging this at `pagination.pageSize` was rejected — but
// "the whole result set" stops at a number instead of at whatever the
// table happens to hold. The walk reads one probe row past the ceiling,
// which is what makes the cut DETECTABLE; `applyNonGridRowCeiling`
// slices it back off at the SAME ceiling. ⛔ Not authorable: an
// authored `limit` / `pagination.pageSize` still cannot reach this
// query, and neither does a datasource's `external.rowCap`, by both
// rulings.
//
// ⛔ The ceiling is a stop condition, not a request size: the walk asks
// in `GANTT_FETCH_STEP` steps, because a host with a maximum page size
// (hosted: 5,000) refuses one `$top` of 10,001 outright, empty object
// or not. See `./ganttRowWalk`.
const result = await fetchGanttRows((params) => adapter.find(resource, params), {
$filter: queryFilter,
$orderby: convertSortToQueryParams(schema.sort),
// The gantt's own ceiling, `GANTT_ROW_CEILING` (objectstack#32421,
// ruling B), not the shared `NON_GRID_ROW_CEILING` the
// non-virtualised tree prices (objectui#7210, ruling a′). The gantt
// still fetches the whole FILTERED result set — a truthful
// `min(start) → max(end)` range and the group rollups need all of it,
// which is why paging this at `pagination.pageSize` was rejected — but
// "the whole result set" stops at a number instead of at whatever the
// table happens to hold. One probe row past the ceiling is what makes
// the cut DETECTABLE; `applyNonGridRowCeiling` slices it back off at
// the SAME ceiling. ⛔ Not authorable: an authored `limit` /
// `pagination.pageSize` still cannot reach this query, and neither
// does a datasource's `external.rowCap`, by both rulings.
...nonGridRowCeilingQuery(GANTT_ROW_CEILING),
...(expand.length > 0 ? { $expand: expand } : {}),
// objectui#10250 — the term and its field narrowing, sent together
// or not at all. See `searchTerm` above.
Expand All @@ -1095,7 +1100,7 @@ export const ObjectGantt: React.FC<ObjectGanttProps> = ({
...(searchFields ? { $searchFields: searchFields } : {}),
}
: {}),
});
}, isCurrent);
const capped = applyNonGridRowCeiling(result, GANTT_ROW_CEILING);
if (isCurrent()) {
setData(capped.rows);
Expand Down
101 changes: 101 additions & 0 deletions ui/packages/plugin-gantt/src/ganttRowWalk.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* The gantt's stepped read (`fetchGanttRows`): no single read asks for more
* than `GANTT_FETCH_STEP` rows, a set that fits one step is one read answered
* as is, and a set walked in steps is read under a unique order and kept once
* per `id`, so offset steps over tied sort keys can neither repeat nor drop a
* row.
*/

import { describe, it, expect, vi } from 'vitest';
import { GANTT_ROW_CEILING, applyNonGridRowCeiling } from '@object-ui/core';
import { GANTT_FETCH_STEP, fetchGanttRows, withIdTieBreak } from './ganttRowWalk';

type Row = { id: string; stage: string };

function rows(n: number): Row[] {
return Array.from({ length: n }, (_, i) => ({ id: String(i + 1), stage: i % 2 ? 'b' : 'a' }));
}

/** Honours `$top` / `$skip`; sorts by `$orderby` only when it names `id`. */
function adapter(store: Row[]) {
return vi.fn(async (params: Record<string, any>) => {
const ordered = params.$orderby && 'id' in params.$orderby
? [...store].sort((x, y) => Number(x.id) - Number(y.id))
: store;
const skip = params.$skip ?? 0;
return { data: ordered.slice(skip, skip + params.$top), total: store.length };
});
}

describe('fetchGanttRows', () => {
it('a set that fits one step is ONE read, answered as is, with the authored order untouched', async () => {
const find = adapter(rows(7));
const answer = await fetchGanttRows(find, { $orderby: { stage: 'desc' } });
expect(find).toHaveBeenCalledTimes(1);
expect(find.mock.calls[0][0]).toEqual({ $orderby: { stage: 'desc' }, $top: GANTT_FETCH_STEP });
expect(answer).toEqual({ data: rows(7), total: 7 });
});

it('never asks one read for more than a step, and stops one row past the ceiling', async () => {
const find = adapter(rows(GANTT_ROW_CEILING + 300));
const answer = await fetchGanttRows(find, {});
for (const [params] of find.mock.calls) expect(params.$top).toBeLessThanOrEqual(GANTT_FETCH_STEP);
const capped = applyNonGridRowCeiling(answer, GANTT_ROW_CEILING);
expect(capped.rows).toHaveLength(GANTT_ROW_CEILING);
expect(capped.truncated).toBe(true);
expect(capped.total).toBe(GANTT_ROW_CEILING + 300);
});

it('walks under a unique order: the authored keys, then `id` in the last key’s direction', async () => {
const find = adapter(rows(GANTT_FETCH_STEP + 5));
await fetchGanttRows(find, { $orderby: { stage: 'desc' } });
const walk = find.mock.calls.slice(1).map(([params]) => params);
expect(walk.length).toBeGreaterThan(0);
for (const params of walk) expect(params.$orderby).toEqual({ stage: 'desc', id: 'desc' });
expect(walk[0].$skip).toBeUndefined();
});

it('keeps a row once when tied keys move it across a step boundary', async () => {
const store = rows(GANTT_FETCH_STEP + 10);
// An adapter that breaks ties differently on each read: every step answers
// the row just before its window again, as an unstable order can.
const find = vi.fn(async (params: Record<string, any>) => {
const skip = params.$skip ?? 0;
const from = Math.max(0, skip - 1);
return { data: store.slice(from, from + params.$top), total: store.length };
});
const answer = (await fetchGanttRows(find, {})) as { data: Row[] };
const ids = answer.data.map((row) => row.id);
expect(new Set(ids).size).toBe(ids.length);
});

it('stops asking once a newer reload owns the screen', async () => {
const find = adapter(rows(GANTT_ROW_CEILING + 300));
let current = true;
find.mockImplementation(async (params: Record<string, any>) => {
if (find.mock.calls.length === 2) current = false;
const skip = params.$skip ?? 0;
const store = rows(GANTT_ROW_CEILING + 300);
return { data: store.slice(skip, skip + params.$top), total: store.length };
});
await fetchGanttRows(find, {}, () => current);
expect(find).toHaveBeenCalledTimes(2);
});
});

describe('withIdTieBreak', () => {
it('appends `id` ascending when nothing was authored', () => {
expect(withIdTieBreak(undefined)).toEqual({ id: 'asc' });
});
it('leaves an order that already names `id` alone', () => {
expect(withIdTieBreak({ id: 'desc', stage: 'asc' })).toEqual({ id: 'desc', stage: 'asc' });
});
});
Loading
Loading