Skip to content

fix: Keep page order and stream pages as they arrive (5.x.x) - #1475

Open
ZPascal wants to merge 3 commits into
cloudfoundry:5.x.xfrom
ZPascal:ordered-pagination-5.x.x
Open

ZPascal wants to merge 3 commits into
cloudfoundry:5.x.xfrom
ZPascal:ordered-pagination-5.x.x

Conversation

@ZPascal

@ZPascal ZPascal commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Port of #1474 to the 5.x.x branch.

Depends on #1473, so this PR also shows its two commits until that one is merged. Only the last commit is new here.

PaginationUtils fetches the additional pages with flatMap, which merges them in whatever order they finish. If page 3 answers before page 2, callers get page 1, 3, 2. That breaks sorted lists, for example UAA lists with sortBy. On top of that, buffer() collects every page in memory first, so nothing is emitted until the last page is back.

Changes (v2, v3 and UAA paging):

  • Use flatMapSequential so pages keep their order.
  • Drop the buffer() / flatMapIterable step so pages are passed on as soon as they are ready.

One thing to be aware of: if a later page fails, callers now see the earlier pages before the error. Before, they only got the error.

Tests: the same order tests as in #1474 for v3 and UAA. Both fail on the old code and pass with this change.

UAA returns itemsPerPage=0 when a list query has no results. The page
count calculation divided by that value and failed with an
ArithmeticException, e.g. in GroupsTest.unmapExternalGroupMappingsByGroupId.
Return only the first response when there are no further pages.
Only return the first page early when there are no more results. If UAA
reports itemsPerPage=0 but still has results, emit an error instead of
completing with a partial list. Also skip the paging pipeline for single
page responses and drop null checks for attributes that are always set.
flatMap merged additional pages in the order they completed, so results
could come back out of page order (e.g. breaking sortBy on UAA lists).
buffer() then held every page in memory and delayed all elements until
the last page was fetched.

Use flatMapSequential so pages keep their order, and drop the
buffer/flatMapIterable step so pages are emitted as soon as they are
ready. Applies to v2, v3 and UAA pagination.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant