Add stats size format options#979
Conversation
📝 WalkthroughWalkthroughThis PR adds a ChangesStats query parameter support
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/test/java/com/meilisearch/sdk/StatsTest.java (1)
33-120: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for optional/default and raw-size responses.
These tests only exercise the
sizeFormat=humanpath and a fully populated query. They never cover the API’s optional/default behavior or raw numeric size payloads, so the currentsizeFormat=nullserialization bug slips through and half of the new response contract remains unverified.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/com/meilisearch/sdk/StatsTest.java` around lines 33 - 120, Add test coverage in StatsTest for the missing StatsQuery paths: verify the default/optional case where sizeFormat is not set still serializes correctly and does not emit a null query value, and add raw-size response coverage for both client.getStats and client.index("movies").getStats using numeric size payloads rather than only the human-formatted contract. Use the existing StatsQuery, getStatsWithQueryParameters, getIndexStatsWithQueryParameters, and statsQuerySerializesParameters tests as the place to extend assertions so the serialization bug and raw response handling are both exercised.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/com/meilisearch/sdk/model/StatsQuery.java`:
- Around line 22-29: The StatsQuery.toQuery() serialization currently always
adds sizeFormat, which produces an unwanted null query value when it is unset.
Update toQuery() so it only calls URLBuilder.addParameter("sizeFormat", ...)
when getSizeFormat() is non-null/non-empty, while keeping
showInternalDatabaseSizes behavior unchanged. Use the StatsQuery and URLBuilder
symbols to locate the optional-parameter handling and align it with the new
contract.
---
Nitpick comments:
In `@src/test/java/com/meilisearch/sdk/StatsTest.java`:
- Around line 33-120: Add test coverage in StatsTest for the missing StatsQuery
paths: verify the default/optional case where sizeFormat is not set still
serializes correctly and does not emit a null query value, and add raw-size
response coverage for both client.getStats and client.index("movies").getStats
using numeric size payloads rather than only the human-formatted contract. Use
the existing StatsQuery, getStatsWithQueryParameters,
getIndexStatsWithQueryParameters, and statsQuerySerializesParameters tests as
the place to extend assertions so the serialization bug and raw response
handling are both exercised.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b537f053-e8f8-49e8-b95c-4bb90a6a4576
📒 Files selected for processing (8)
.code-samples.meilisearch.yamlsrc/main/java/com/meilisearch/sdk/Client.javasrc/main/java/com/meilisearch/sdk/Index.javasrc/main/java/com/meilisearch/sdk/InstanceHandler.javasrc/main/java/com/meilisearch/sdk/model/IndexStatsWithSizeFormat.javasrc/main/java/com/meilisearch/sdk/model/StatsQuery.javasrc/main/java/com/meilisearch/sdk/model/StatsWithSizeFormat.javasrc/test/java/com/meilisearch/sdk/StatsTest.java
| public String toQuery() { | ||
| URLBuilder urlb = | ||
| new URLBuilder() | ||
| .addParameter( | ||
| "showInternalDatabaseSizes", | ||
| this.getShowInternalDatabaseSizes()) | ||
| .addParameter("sizeFormat", this.getSizeFormat()); | ||
| return urlb.getURL(); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Omit sizeFormat when it is unset.
Line 28 always passes sizeFormat into URLBuilder, but that helper only skips empty strings. With new StatsQuery() or new StatsQuery().setShowInternalDatabaseSizes(true), this serializes as ?sizeFormat=null, which violates the new optional-parameter contract and breaks the request.
Proposed fix
public String toQuery() {
- URLBuilder urlb =
- new URLBuilder()
- .addParameter(
- "showInternalDatabaseSizes",
- this.getShowInternalDatabaseSizes())
- .addParameter("sizeFormat", this.getSizeFormat());
+ URLBuilder urlb =
+ new URLBuilder()
+ .addParameter(
+ "showInternalDatabaseSizes",
+ this.getShowInternalDatabaseSizes());
+ if (this.getSizeFormat() != null && !this.getSizeFormat().isEmpty()) {
+ urlb.addParameter("sizeFormat", this.getSizeFormat());
+ }
return urlb.getURL();
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public String toQuery() { | |
| URLBuilder urlb = | |
| new URLBuilder() | |
| .addParameter( | |
| "showInternalDatabaseSizes", | |
| this.getShowInternalDatabaseSizes()) | |
| .addParameter("sizeFormat", this.getSizeFormat()); | |
| return urlb.getURL(); | |
| public String toQuery() { | |
| URLBuilder urlb = | |
| new URLBuilder() | |
| .addParameter( | |
| "showInternalDatabaseSizes", | |
| this.getShowInternalDatabaseSizes()); | |
| if (this.getSizeFormat() != null && !this.getSizeFormat().isEmpty()) { | |
| urlb.addParameter("sizeFormat", this.getSizeFormat()); | |
| } | |
| return urlb.getURL(); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/main/java/com/meilisearch/sdk/model/StatsQuery.java` around lines 22 -
29, The StatsQuery.toQuery() serialization currently always adds sizeFormat,
which produces an unwanted null query value when it is unset. Update toQuery()
so it only calls URLBuilder.addParameter("sizeFormat", ...) when getSizeFormat()
is non-null/non-empty, while keeping showInternalDatabaseSizes behavior
unchanged. Use the StatsQuery and URLBuilder symbols to locate the
optional-parameter handling and align it with the new contract.
Pull Request
Related issue
Fixes #966
What does this PR do?
StatsQuerysupport for theshowInternalDatabaseSizesandsizeFormatquery parameters.internalDatabaseSizesas a flexible map..code-samples.meilisearch.yamlforget_index_stats_1andget_indexes_stats_1.PR checklist
Please check if your PR fulfills the following requirements:
Tests
.\gradlew.bat testClasses.\gradlew.bat test --tests com.meilisearch.sdk.StatsTest --init-script <disable-jacoco> -x jacocoTestReport -x jacocoTestCoverageVerification --rerun-tasksThank you so much for contributing to Meilisearch!
Summary by CodeRabbit
New Features
Bug Fixes
Tests