Skip to content

fix(clients): browseSynonyms pagination (CR-11727) - #6652

Merged
Fluf22 merged 2 commits into
mainfrom
fix/java-browse-synonyms-pagination
Jul 3, 2026
Merged

Fluf22 merged 2 commits into
mainfrom
fix/java-browse-synonyms-pagination

Conversation

@Fluf22

@Fluf22 Fluf22 commented Jul 2, 2026 •

Copy link
Copy Markdown
Collaborator

What & why

🎟 CR-11727

SearchClient.browseSynonyms (Java) incremented an internal page counter but never wrote it back to the request params, so every call re-requested page=0. With a full first page (β‰₯1000 synonyms) the stop condition never triggered β€” the iterator looped and returned duplicate hits until it ran out of memory. Fixed to write the page back before each searchSynonyms call (mirrors browseRules); the no-arg overload no longer passes null.

While auditing the other clients I found a related bug in PHP: SynonymIterator/RuleIterator stopped after the first full page (the guard compared the cumulative key to the current page's hit count), silently truncating results to hitsPerPage. They now stop only on a non-full page, like every other client. JavaScript, Kotlin, Scala and Swift were already correct.

Tests

Added a browseSynonyms pagination regression test in all six implementing languages (Java, PHP, JavaScript, Kotlin, Scala, Swift): serve a full page 0 then a partial page 1, and assert the client requests pages 0 β†’ 1, aggregates every hit exactly once, and terminates. All pass locally.

Notes

  • Only the source fix + hand-written tests are included β€” CI regenerates the client code.
  • The Kotlin test lives in jvmTest (the client's common test set has no coroutine runner).

Java `browseSynonyms` incremented an internal page counter but never wrote it
back to the params, so every request re-fetched page 0. With a full first page
(1000 synonyms) the stop condition was never reached: the iterator looped and
returned duplicate hits until it ran out of memory. Mirror `browseRules` by
writing the page back before each `searchSynonyms` call, and stop the no-arg
overload from passing null params.

While auditing the other clients, PHP had a related pagination bug: the Synonym
and Rule iterators' stop-guard compared the cumulative key to the current page's
hit count, so they stopped after the first full page and silently truncated
results to hitsPerPage. Stop only on a non-full page instead.

Add per-language regression tests (Java, PHP, JavaScript, Kotlin, Scala, Swift)
that serve a full page 0 then a partial page 1 and assert the iterator requests
pages 0 then 1, aggregates every hit exactly once, and terminates.
@algolia-api-clients-automation-bot

algolia-api-clients-automation-bot Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

πŸ’₯ Breaking changes detected !!

Either this PR or a previous PR not released yet introduced breaking changes, be careful when merging.
You can find the details in the 'client java@21' CI job.

βœ”οΈ Code generated!

Name Link
πŸͺ“ Triggered by c0e0d287b9207617d3594fbbcc97931efd4d06b1
πŸƒ Generated commit 3867b747538e603f3e4a6400aa0d522f045072af
🌲 Generated branch generated/fix/java-browse-synonyms-pagination
πŸ“Š Benchmark results

Benchmarks performed on the method using a mock server, the results might not reflect the real-world performance.

Language Req/s
javascript 2224
php 1651
java 1098
swift 731
scala 23

`List.of` is Java 9+, but the Java client targets Java 8 (the `client java@8`
CI job failed). Replace it with `Arrays.asList`.
@Fluf22
Fluf22 marked this pull request as ready for review July 2, 2026 09:40
@Fluf22
Fluf22 requested a review from a team as a code owner July 2, 2026 09:40

@eric-zaharia eric-zaharia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@Fluf22 Fluf22 self-assigned this Jul 3, 2026
@Fluf22
Fluf22 merged commit f258a66 into main Jul 3, 2026
21 checks passed
@Fluf22
Fluf22 deleted the fix/java-browse-synonyms-pagination branch July 3, 2026 15:31
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.

2 participants