Skip to content

Add index compaction#664

Merged
curquiza merged 2 commits intomeilisearch:mainfrom
psylone:feat/support-v1.23
Dec 30, 2025
Merged

Add index compaction#664
curquiza merged 2 commits intomeilisearch:mainfrom
psylone:feat/support-v1.23

Conversation

@psylone
Copy link
Copy Markdown
Contributor

@psylone psylone commented Dec 12, 2025

Pull Request

Related issue

Fixes #656

What does this PR do?

  • Add index compaction

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?

Summary by CodeRabbit

  • New Features

    • Index compaction is now available. Users can compact indexes asynchronously and track progress via task status.
  • Tests

    • Added automated tests covering the index compaction workflow and task completion.
  • Documentation / Code Samples

    • Added a sample showing how to invoke index compaction.
  • Chores

    • Linting metadata updated (tooling config adjustments).

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 12, 2025

📝 Walkthrough

Walkthrough

Adds an Index#compact method that POSTs to /indexes/{uid}/compact, returns a Models::Task, plus a new RSpec verifying the flow and a code-sample entry demonstrating usage. (<=50 words)

Changes

Cohort / File(s) Summary
Index compaction API method
lib/meilisearch/index.rb
New public instance method compact sending POST /indexes/{uid}/compact and returning a Models::Task.
Test coverage
spec/meilisearch/index/compact_spec.rb
New RSpec verifying task type indexCompaction, waiting for completion, and asserting success.
Code samples
.code-samples.meilisearch.yaml
Added compact_index_1 sample showing client.index('INDEX_UID').compact.
Lint metadata
.rubocop_todo.yml
RuboCop metadata/timestamps and metric counters updated (non-functional).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Developer (calls client)
  participant Client as MeiliSearch::Client
  participant Index as MeiliSearch::Index
  participant HTTP as HTTP Adapter
  participant Server as Meilisearch Server

  rect rgb(230,240,255)
    Dev->>Client: client.index('uid').compact
    Client->>Index: resolve index object
    Index->>HTTP: POST /indexes/uid/compact
    HTTP->>Server: HTTP request
    Server-->>HTTP: 202 Accepted + task payload
    HTTP-->>Index: response body
    Index-->>Client: Models::Task instance
    Client-->>Dev: Task returned (async operation started)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped a tiny patch today,
A compact route to clear the way,
POSTed a tidy little task,
The index hums — no need to ask.
Hooray for neatness, hip hooray! ✨

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 index compaction' clearly and concisely summarizes the main change—adding support for the index compaction API feature.
Linked Issues check ✅ Passed All three coding requirements from issue #656 are satisfied: the compact method is added to the Index class, a test case is implemented in compact_spec.rb, and a code sample is added to .code-samples.meilisearch.yaml.
Out of Scope Changes check ✅ Passed Changes to .rubocop_todo.yml appear to be auxiliary updates related to linting enforcement of the new code rather than out-of-scope modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

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.

curquiza
curquiza previously approved these changes Dec 29, 2025
@curquiza curquiza added the enhancement New feature or request label Dec 29, 2025
@curquiza curquiza enabled auto-merge December 29, 2025 17:41
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4e7ab12) to head (448503f).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #664   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines          806       809    +3     
=========================================
+ Hits           806       809    +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.

@curquiza
Copy link
Copy Markdown
Member

@psylone can you fix the linting issue please?

@psylone
Copy link
Copy Markdown
Contributor Author

psylone commented Dec 29, 2025

@curquiza thanks for approve! What do you think, should we just increase Metrics/ClassLength cop or refactor Meilisearch::Index class?

auto-merge was automatically disabled December 29, 2025 19:32

Head branch was pushed to by a user without write access

Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
.rubocop_todo.yml (1)

16-17: Consider refactoring the Index class to reduce its size.

The Index class has grown to 541 lines and handles multiple responsibilities (documents, search, tasks, stats, settings with many subcategories). While this increase is minimal for the current feature, consider extracting related functionality into separate modules or concern classes in a future refactor (e.g., IndexSettings, IndexDocuments, IndexSearch).

For now, accepting the increased limit is reasonable given the small change, but this addresses your question about whether to refactor or increase the limit.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd9f0e1 and 448503f.

📒 Files selected for processing (4)
  • .code-samples.meilisearch.yaml
  • .rubocop_todo.yml
  • lib/meilisearch/index.rb
  • spec/meilisearch/index/compact_spec.rb
🚧 Files skipped from review as they are similar to previous changes (2)
  • spec/meilisearch/index/compact_spec.rb
  • .code-samples.meilisearch.yaml
🧰 Additional context used
🧬 Code graph analysis (1)
lib/meilisearch/index.rb (2)
lib/meilisearch/http_request.rb (1)
  • http_post (39-51)
lib/meilisearch/client.rb (1)
  • task_endpoint (490-492)
🔇 Additional comments (1)
lib/meilisearch/index.rb (1)

701-712: LGTM! Well-implemented compaction method.

The implementation correctly follows the established pattern for asynchronous operations in this codebase. The documentation is clear and includes a helpful note about disk space requirements.

@psylone
Copy link
Copy Markdown
Contributor Author

psylone commented Dec 29, 2025

Decided to increase the Metrics/ClassLength limit. I can suggest refactoring the Meilisearch::Index class in a separate PR.

Update: done in #677

@curquiza
Copy link
Copy Markdown
Member

Decided to increase the Metrics/ClassLength limit. I can suggest refactoring the Meilisearch::Index class in a separate PR.

Good choice! Indeed, something to do in another PR

Copy link
Copy Markdown
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

thanks!

@curquiza curquiza added this pull request to the merge queue Dec 30, 2025
Merged via the queue into meilisearch:main with commit 65f4370 Dec 30, 2025
8 checks passed
@psylone psylone deleted the feat/support-v1.23 branch January 15, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1.23] Add support for compacting database indexes

2 participants