Repository navigation
Description
Description
BrowserAPIImpl#getContentByChunks reads the folder listing in fixed 400-row
chunks, permission-filters each chunk in Java, and repeats until it has a full
page of visible items. The chunk size never changes, and every chunk re-runs the
whole candidate query with a larger OFFSET.
PostgreSQL cannot jump to row N — it produces and discards the N preceding rows
— so N chunks at growing offsets re-read the prefix N times. The cost is
quadratic in chunk count, and the chunk count is driven by how much the
permission filter discards, not by folder size:
| user | visible in a 21,383-child folder | chunks |
|---|---|---|
| administrator | everything | 1 |
| reads 1.4% | 151 of 11,000 | 8 |
| reads none | 0 | 54 |
The loop already knows the visible/read ratio after its first chunk, so it can
size the next fetch to what is actually needed instead of asking for 400 rows 54
times. Total rows the request must read barely changes; what collapses is how
many times the prefix is re-read.
This predates #37229 — the materialized CTE raised the per-chunk constant and
made it visible, but the quadratic was already there.
Measured
Prototype (~40 lines, behind BROWSER_DB_CHUNK_ADAPTIVE) measured on a local
instance built from main @ ba7ab6f0a2, 59k identifiers, PostgreSQL 18,
7 repetitions per case, warmup discarded, VACUUM ANALYZE before each run:
| case | today | adaptive | |
|---|---|---|---|
| 21,383-child folder, user reads none | 5,026 ms | 1,258 ms | -75% |
| 21,383-child folder, user reads 151 | 5,009 ms | 1,344 ms | -73% |
| 11,000-child folder, user reads none | 1,619 ms | 669 ms | -59% |
| 11,000-child folder, user reads 151 | 510 ms | 242 ms | -52% |
| any folder, administrator | 192 ms | 202 ms | unchanged |
Blocks read per request fall 9x (5,876,712 → 652,968). Chunks fall from 54 to 6.
Full page walks following the cursor to the end return identical items in
identical order, no duplicated or skipped pages.
The worst case lands at 1.3 s — below the 3.5 s it cost before #37229 existed,
so this does not merely cancel that issue's regression, it improves on the
behaviour that preceded it.
Approach
Two regimes, both in the chunk loop — no change to the SQL or to the permission
filter:
- Some rows were visible. The ratio is measurable: request what is still
needed at that ratio, times a safety factor, since the ratio is a sample and
the next stretch of the folder may be sparser. - No rows were visible. There is no ratio to extrapolate from, so double
instead. Geometric growth bounds the overshoot at one chunk's worth of extra
rows while turning a linear walk into a logarithmic one.
Never below the caller's current chunk size, never above a configured ceiling or
what is left of BROWSER_DB_MAX_SCAN_ROWS.
Scope to the permission-only path. The Elasticsearch-narrowed path is bounded by
elapsed time and a separate hard cap (#37211, #37184); growing its chunks would
change how those bounds behave.
Ruled out
Keyset pagination was prototyped and measured as a dead end for this query:
6% slower than OFFSET, blocks read essentially unchanged (5,767,884 vs
5,876,712). It converts a skip into a seek only when an index supplies the order;
here the order comes from an explicit sort over a four-table join, and no index
can provide it because mod_date lives in contentlet while parent_path lives
in identifier. The predicate trims rows only after the work is already done.
Recorded so nobody spends the time twice.
Acceptance Criteria
- Tests written, dev-approved, and confirmed failing before any implementation
code (Constitution Principle V) - The chunk size grows from the observed permission-visible ratio, and falls
back to geometric growth when no rows were visible - Chunk size never drops below the caller's configured size and never exceeds
either the configured ceiling or the remaining scan budget - A listing returns the same items in the same order with the feature on and
off, verified by walking every page of a folder to the end — no duplicated
or skipped pages, on an administrator and on a permission-limited user - The worst case in the test matrix (a large folder browsed by a user who can
read none of it) improves by at least half against the current behaviour - An administrator's request is unchanged: still one chunk, no measurable
latency difference - The Elasticsearch-narrowed path is untouched, verified against the cases
Content Drive: adding a content-type filter to the global search hides matches the search alone found #37211 and Content Drive: field filter re-scans the folder candidate query up to 4x per request #37184 added - Behaviour verified unchanged when combined with tag, workflow and field
filters - The feature is behind a configuration flag that restores today's fixed
chunk size
Priority
Medium
Additional Context
Found while running the permission-scoped QA for #37229 — see the verification
comment on that issue for the full test conditions and the caveat about dataset
scale (this was measured on 59k identifiers, not the 418k reference dataset from
#37183).
Coordinate with #37184, which tunes the chunk multiplier for field filters and
shares this loop.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Sep 28, 2026
PRs linked to this issue
docs(content-drive): add per-step growth cap for clustered visibility (…
test(content-drive): adaptive DB chunk sizing tests (#37665)
feat(content-drive): size permission-only listing chunks from the vis…
perf(content-drive): lower the adaptive chunk ceiling default to 2000 (…
spec(content-drive): adaptive chunk ceiling default is 2000 per revie…
dario-daza commentedon Oct 9, 2026
✅ QA: passed
Tested on image
26.10.08-01(includes #37838), 6 GB heap, togglingBROWSER_DB_CHUNK_ADAPTIVEon and off on the same instance.Results:
falserestores the old behaviour immediately, with no restart.Note: on a 1 GB heap that was already full, the feature was slower than off under concurrent load. It loads up to 2,000 items per chunk, so it needs some memory headroom.