Skip to content

Conversation

@kumarUjjawal
Copy link
Contributor

@kumarUjjawal kumarUjjawal commented Oct 29, 2025

Pull Request

Related issue

Fixes #671

What does this PR do?

  • I also added examples in the .code-samples.meilisearch.yaml

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • New Features

    • Added support for the Batches API — list batches with pagination and fetch batch details.
    • Included asynchronous code samples demonstrating listing batches, paginating results, and fetching a single batch.
  • Tests

    • Added unit tests covering batch parsing and retrieval behaviors.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

Walkthrough

Adds a new Batches API: a public batches module with data models (Batch, BatchesResults), a BatchesQuery builder with execution, three async client methods (get_batches, get_batches_with, get_batch), new code samples, and unit tests.

Changes

Cohort / File(s) Summary
Code samples
\.code-samples.meilisearch.yaml
Added three async examples under reset_typo_tolerance_1: get_all_batches_1, get_batch_1, get_all_batches_paginating_1 demonstrating client.get_batches_with(...), client.get_batch(uid), and pagination usage.
Batches module
src/batches.rs
New module defining Batch (fields: uid, enqueued_at, started_at, finished_at, index_uid, task_uids, batch_strategy), BatchStrategy enum, BatchesResults (results + pagination), BatchesQuery<'a, Http> builder with new, with_limit, with_from, and execute(), plus unit tests for parsing and request serialization.
Client methods
src/client.rs
Added async methods: get_batches(), get_batches_with(&BatchesQuery), and get_batch(uid). Note: the three method definitions appear duplicated within the same impl block in this diff.
Crate export
src/lib.rs
Exported new public module: pub mod batches; with doc comment exposing the Batches API at crate level.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Client
    participant QueryBuilder
    participant HTTP

    rect rgba(200,230,255,0.35)
    User->>Client: get_batches()
    Client->>HTTP: GET /batches
    HTTP-->>Client: 200 + BatchesResults
    Client-->>User: Ok(BatchesResults)
    end

    rect rgba(220,255,200,0.35)
    User->>Client: get_batches_with(query)
    Client->>QueryBuilder: read limit/from
    QueryBuilder-->>Client: query params
    Client->>HTTP: GET /batches?limit=X&from=Y
    HTTP-->>Client: 200 + BatchesResults
    Client-->>User: Ok(BatchesResults)
    end

    rect rgba(255,230,200,0.35)
    User->>Client: get_batch(uid)
    Client->>HTTP: GET /batches/{uid}
    HTTP-->>Client: 200 + Batch
    Client-->>User: Ok(Batch)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Review serde attributes and camelCase mappings for Batch, BatchStrategy, and BatchesResults.
  • Inspect BatchesQuery param encoding and that execute() delegates correctly to client methods.
  • Confirm get_batch URL formatting and error propagation.
  • Resolve duplicated method definitions in src/client.rs (likely causes compile errors).
  • Verify unit tests and new code sample correctness.

Poem

🐰 I hopped through code with eager paws,
New batches stitched between the draws,
One fetch, many pages, queries hum,
I nibble bugs and watch them run. ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Add batchStrategy field to batches" directly reflects the primary objective from issue #671. It is specific and clear, identifying the core change (the batchStrategy field) without unnecessary noise. While the PR implements a broader batches module, the title appropriately focuses on the key feature requirement, which is the specific field addition for v1.15 alignment. The title would be clear to teammates scanning the commit history.
Linked Issues Check ✅ Passed The PR successfully addresses all coding-related requirements from issue #671. The batchStrategy field is now included in the Batch struct with proper serialization support via the BatchStrategy enum. Three new methods (get_batches, get_batches_with, get_batch) expose batches API functionality that returns responses containing the new field. Unit tests are implemented to validate BatchStrategy parsing and batch retrieval operations. Code samples demonstrating usage of the new API are provided in .code-samples.meilisearch.yaml. All primary objectives are met.
Out of Scope Changes Check ✅ Passed All code changes are directly related to implementing batches API support with the batchStrategy field as required by issue #671. The new batches.rs module, query builder structures, and client methods all serve the primary objective of exposing batch operations with the new field. Code samples in .code-samples.meilisearch.yaml demonstrate the new functionality. No changes appear unrelated to the stated requirements. However, the PR summary notes that three method signatures appear duplicated in client.rs, which suggests a potential code quality issue that should be resolved before merging.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dce6c21 and 5912be2.

📒 Files selected for processing (3)
  • .code-samples.meilisearch.yaml (1 hunks)
  • src/batches.rs (1 hunks)
  • src/client.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .code-samples.meilisearch.yaml
🧰 Additional context used
🧬 Code graph analysis (2)
src/client.rs (1)
src/request.rs (1)
  • query (39-47)
src/batches.rs (1)
src/client.rs (3)
  • new (54-66)
  • None (1532-1532)
  • None (1611-1611)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: integration-tests
🔇 Additional comments (8)
src/client.rs (3)

1115-1141: LGTM! Clean implementation of get_batches.

The method follows the established pattern for listing resources and includes clear documentation with a usage example.


1143-1172: LGTM! Pagination query method follows established patterns.

The implementation correctly accepts a BatchesQuery and passes it as a query parameter, consistent with other query builder methods in the codebase.


1174-1199: LGTM! Single batch retrieval method is well-implemented.

The method correctly constructs the URL path with the batch UID and returns a single Batch result, following the same pattern as get_task.

src/batches.rs (5)

9-34: LGTM! Batch struct is well-defined.

The structure correctly models the batch response. The uid field at line 13 no longer has #[serde(default)], addressing the previous review concern. Timestamp fields appropriately use #[serde(default, with = "time::serde::rfc3339::option")] for optional RFC 3339 parsing.


36-48: LGTM! Excellent forward compatibility design.

The BatchStrategy enum uses #[non_exhaustive] and includes an Unknown variant with #[serde(other)], ensuring the SDK can gracefully handle new batch strategies introduced in future Meilisearch versions.


50-60: LGTM! Standard pagination results structure.

The BatchesResults struct follows the established pattern of other results types in the codebase (e.g., TasksResults, IndexesResults), with appropriate optional pagination fields.


62-102: LGTM! Query builder follows established patterns.

The BatchesQuery implementation correctly follows the builder pattern used throughout the codebase, with chainable with_* methods and an execute() method that delegates to the client. The use of #[must_use] on constructors and builders is appropriate.


104-199: LGTM! Comprehensive test coverage.

The tests effectively validate:

  • Parsing of BatchStrategy variants from JSON responses
  • Single batch retrieval by UID
  • Query parameter serialization for pagination (limit and from)

All tests use mockito appropriately to mock server responses.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (7)
.code-samples.meilisearch.yaml (2)

452-457: Consider showcasing paginated usage

Add an example using BatchesQuery (with_limit, with_from) to mirror other paginated samples and the new API.

 get_all_batches_1: |-
-  let batches: BatchesResults = client
-    .get_batches()
-    .await
-    .unwrap();
+  let mut query = meilisearch_sdk::batches::BatchesQuery::new(&client);
+  query.with_limit(20);
+  let batches: meilisearch_sdk::batches::BatchesResults =
+    client.get_batches_with(&query).await.unwrap();

458-461: Minor: clarify uid type in the example

Use a named u32 variable to hint the expected type (helps readers).

 get_batch_1: |-
-  let batch: Batch = client
-    .get_batch(42)
+  let uid: u32 = 42;
+  let batch: meilisearch_sdk::batches::Batch = client
+    .get_batch(uid)
     .await
     .unwrap();
src/client.rs (1)

1115-1157: Add small doctest snippets for parity with other client methods

Follow existing style by adding minimal examples to get_batches, get_batches_with, and get_batch to keep docs cohesive and catch regressions.

src/batches.rs (4)

30-35: Type safety for batch_strategy

If the set of values is known/stable (e.g., time_limit_reached, size_limit_reached), prefer an enum with #[serde(rename_all = "snake_case")] for compile-time safety. Keep Option<...> if it’s not always present.


39-49: Align pagination field types with existing Results structs

For consistency with other SDK results (e.g., indexes/tasks), consider using the same integer widths (often u32) for total, limit, from, next unless the API guarantees wider ranges.


65-91: Query builder looks good; add a query-serialization test

Implementation mirrors other builders. Add a test asserting the presence of ?limit=/?from= in the request (via mockito matchers) to lock the wire format.

// sketch
let _m = s.mock("GET", "/batches")
    .match_query(Matcher::AllOf(vec![
        Matcher::UrlEncoded("limit".into(), "2".into()),
        Matcher::UrlEncoded("from".into(), "40".into()),
    ]))
    .with_status(200).with_body(r#"{"results":[]}"#).create_async().await;

137-161: Tests: single-batch retrieval OK

Covers minimal payload. Consider adding a case with missing optional fields to ensure defaults behave as expected.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e90a3c2 and 7166542.

📒 Files selected for processing (4)
  • .code-samples.meilisearch.yaml (1 hunks)
  • src/batches.rs (1 hunks)
  • src/client.rs (1 hunks)
  • src/lib.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/client.rs (1)
src/request.rs (1)
  • query (39-47)
src/batches.rs (1)
src/client.rs (1)
  • new (54-66)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: integration-tests
🔇 Additional comments (3)
src/lib.rs (1)

233-234: Module exposure looks good

Publicly exporting batches with a brief doc is consistent with the crate’s layout.

src/client.rs (1)

1115-1157: Batches endpoints wiring is correct

HTTP method, paths, and status codes are consistent with existing patterns.

src/batches.rs (1)

97-135: Tests: happy-path coverage is solid

Good coverage for parsing timestamps and batchStrategy.

@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

❌ Patch coverage is 97.60000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.41%. Comparing base (e90a3c2) to head (5912be2).

Files with missing lines Patch % Lines
src/batches.rs 96.62% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #722      +/-   ##
==========================================
+ Coverage   86.18%   86.41%   +0.22%     
==========================================
  Files          20       21       +1     
  Lines        6263     6388     +125     
==========================================
+ Hits         5398     5520     +122     
- Misses        865      868       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

kumarUjjawal and others added 2 commits October 29, 2025 17:59
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

[v1.15] Add batchStrategy field to batches

1 participant