Skip to content

Conversation

ziyieses
Copy link

@ziyieses ziyieses commented Aug 29, 2025

Pull Request

Related issue

Fixes #597

What does this PR do?

  • Add reverse as a parameter to fetch and sort tasks by the time enqueued
  • Use FluentAssertions only for integration test

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 an option to view tasks in reverse chronological order by their enqueue time when listing tasks.
  • Documentation
    • Updated user-facing API documentation to describe the new task ordering option.
  • Tests
    • Added automated tests to validate reverse ordering of tasks by enqueue time.

Copy link

coderabbitai bot commented Aug 29, 2025

Walkthrough

Added an optional reverseOrder parameter to Index.GetTasksAsync to allow client-side ordering of returned tasks by EnqueuedAt when true; included System.Linq, updated XML docs, and added a unit test validating task ordering when reverseOrder is enabled.

Changes

Cohort / File(s) Summary of Changes
Tasks retrieval API
src/Meilisearch/Index.Tasks.cs
Added using System.Linq;. Extended GetTasksAsync signature to accept bool reverseOrder = false. When reverseOrder is true, sorts Results by EnqueuedAt (using OrderBy) and returns a new TasksResults with the reordered Results, preserving Limit, From, Next, and Total. Updated XML documentation to include reverseOrder.
Unit tests
tests/Meilisearch.Tests/TaskInfoTests.cs
Added ReverseTasksByEnqueuedAt test: creates documents, calls GetTasksAsync(..., reverseOrder: true), asserts response non-null, converts results to list, and verifies returned tasks are ordered by EnqueuedAt in ascending order corresponding to the implemented OrderBy.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Index
  participant MeiliAPI

  Caller->>Index: GetTasksAsync(query, cancellationToken, reverseOrder)
  activate Index
  Index->>MeiliAPI: GET /tasks (with query)
  MeiliAPI-->>Index: TasksResults { Results[], Limit, From, Next, Total }
  alt reverseOrder == true
    Note over Index: Order Results by EnqueuedAt (ascending) using LINQ
    Index-->>Caller: TasksResults { ordered Results, meta preserved }
  else reverseOrder == false
    Index-->>Caller: TasksResults { original Results, meta preserved }
  end
  deactivate Index
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective (issue#) Addressed Explanation
Add reverse parameter for fetching tasks (#597)
Add integration/tests for reverse behavior (#597)

Poem

A rabbit hops through lines of code and cheer,
"Flip the tasks!" it hums — the order's clear.
EnqueuedAt aligned, neat row by row,
Tests give a wink and off we go.
🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4f229ee and a84c702.

📒 Files selected for processing (1)
  • tests/Meilisearch.Tests/TaskInfoTests.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Meilisearch.Tests/TaskInfoTests.cs
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 3

🧹 Nitpick comments (3)
tests/Meilisearch.Tests/TaskInfoTests.cs (1)

110-112: Reduce flakiness: ensure distinct EnqueuedAt timestamps.

Back-to-back enqueues can share the same timestamp, making sort order non-deterministic. Add small delays between enqueues.

-            var task1 = await _index.AddDocumentsAsync(new[] { new Movie { Id = "6" } });
-            var task2 = await _index.AddDocumentsAsync(new[] { new Movie { Id = "7" } });
-            var task3 = await _index.AddDocumentsAsync(new[] { new Movie { Id = "8" } });
+            var task1 = await _index.AddDocumentsAsync(new[] { new Movie { Id = "6" } });
+            await Task.Delay(50);
+            var task2 = await _index.AddDocumentsAsync(new[] { new Movie { Id = "7" } });
+            await Task.Delay(50);
+            var task3 = await _index.AddDocumentsAsync(new[] { new Movie { Id = "8" } });
src/Meilisearch/Index.Tasks.cs (2)

17-17: Clarify semantics of reverseOrder.

“Reverse the order of the tasks by EnqueuedAt” is ambiguous (reverse of server default vs. explicit direction). If the intent is “newest first,” document it explicitly.

-        /// <param name="reverseOrder">Whether to reverse the order of the tasks by EnqueuedAt.</param>
+        /// <param name="reverseOrder">
+        /// If true, return results ordered by EnqueuedAt descending (newest first). If false, preserve server order.
+        /// Note: pagination fields (From/Next) still reflect server ordering.
+        /// </param>

17-33: Server-side sort is preferable to client-side reordering.

Client-side resorting breaks global ordering across pages. If the Tasks API supports sort (e.g., by enqueuedAt asc/desc), surface it in TasksQuery and pass it through TaskEndpoint to keep pagination consistent.

I can draft a follow-up PR adding a Sort or OrderBy option to TasksQuery and wiring it into TaskEndpoint.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1592132 and 4f229ee.

📒 Files selected for processing (2)
  • src/Meilisearch/Index.Tasks.cs (2 hunks)
  • tests/Meilisearch.Tests/TaskInfoTests.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/Meilisearch.Tests/TaskInfoTests.cs (2)
src/Meilisearch/Index.Tasks.cs (3)
  • Task (19-33)
  • Task (41-44)
  • Task (54-61)
src/Meilisearch/TaskEndpoint.cs (6)
  • Task (27-32)
  • Task (40-47)
  • Task (55-62)
  • Task (70-74)
  • Task (82-86)
  • Task (96-117)
src/Meilisearch/Index.Tasks.cs (5)
src/Meilisearch/TasksResults.cs (2)
  • TasksResults (10-34)
  • TasksResults (12-18)
src/Meilisearch/TaskResource.cs (2)
  • TaskResource (10-87)
  • TaskResource (12-26)
src/Meilisearch/QueryParameters/TasksQuery.cs (1)
  • TasksQuery (9-75)
src/Meilisearch/TaskEndpoint.cs (2)
  • TaskEndpoint (17-130)
  • TaskEndpoint (125-129)
src/Meilisearch/Index.cs (1)
  • TaskEndpoint (148-157)

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.12.0] Add reverse parameter for fetching tasks
1 participant