Skip to content

feat(stats): add query params for Meilisearch v1.44 showInternalDatabaseSizes and sizeFormat#916

Open
arieleli01212 wants to merge 2 commits into
meilisearch:mainfrom
arieleli01212:feat/stats-v1.44-params
Open

feat(stats): add query params for Meilisearch v1.44 showInternalDatabaseSizes and sizeFormat#916
arieleli01212 wants to merge 2 commits into
meilisearch:mainfrom
arieleli01212:feat/stats-v1.44-params

Conversation

@arieleli01212

@arieleli01212 arieleli01212 commented Jun 1, 2026

Copy link
Copy Markdown

Closes #915.

Adds support for the two new query parameters introduced in Meilisearch v1.44.0 for the stats endpoints.

Changes

src/Contracts/Stats.phpdatabaseSize and usedDatabaseSize widened from int to int|string to accommodate human-readable responses when sizeFormat='human'

src/Contracts/IndexStats.php — same widening for rawDocumentDbSize and avgDocumentSize; new optional internalDatabaseSizes: ?array field (present only when showInternalDatabaseSizes=true; keys subject to change per spec)

src/Endpoints/Stats.php — overrides show() to accept a $query array passed through to http->get

src/Endpoints/Delegates/HandlesSystem.phpstats(array $query = []) passes query to Stats::show()

src/Endpoints/Indexes.phpstats(array $query = []) passes query to http->get

.code-samples.meilisearch.yaml — updated get_index_stats_1 and get_indexes_stats_1

All existing callers with no arguments continue to work unchanged.

Summary

This pull request adds support for two new query parameters introduced in Meilisearch v1.44.0 to the stats endpoints: showInternalDatabaseSizes and sizeFormat.

Key Changes

Contracts Updated

  • src/Contracts/Stats.php: databaseSize and usedDatabaseSize widened from int to int|string to support both raw byte counts and human-readable strings.
  • src/Contracts/IndexStats.php: rawDocumentDbSize and avgDocumentSize widened from int to int|string; added optional internalDatabaseSizes: ?array (map of internal DB names to sizes) and a getInternalDatabaseSizes(): ?array getter. fromArray() updated to accept the new field.

Endpoints and Delegates Enhanced

  • src/Endpoints/Stats.php: added show(array $query = []): ?array to forward query parameters to the HTTP GET for /stats.
  • src/Endpoints/Delegates/HandlesSystem.php: stats() signature changed to stats(array $query = []): StatsContract and forwards $query to Stats::show().
  • src/Endpoints/Indexes.php: stats(array $query = []): array now forwards the query array to the HTTP GET request for index stats.

Documentation Samples

  • .code-samples.meilisearch.yaml: updated get_index_stats_1 and get_indexes_stats_1 to call stats with showInternalDatabaseSizes: true and sizeFormat: 'human'.

Backward Compatibility

All additions are optional and default to prior behavior; callers that invoke stats() without arguments continue to work unchanged.

Related Issues

Closes #915

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cf912b08-ba99-4d27-9f65-81829c318b6f

📥 Commits

Reviewing files that changed from the base of the PR and between 74b4f8e and 0b36ce2.

📒 Files selected for processing (2)
  • src/Contracts/IndexStats.php
  • src/Contracts/Stats.php
💤 Files with no reviewable changes (2)
  • src/Contracts/Stats.php
  • src/Contracts/IndexStats.php

📝 Walkthrough

Walkthrough

This PR widens Stats and IndexStats size fields to accept int|string, adds an optional internalDatabaseSizes map and getter, adds a parameterized Stats::show(array $query = []) endpoint, updates HandlesSystem::stats() and Indexes::stats() to accept and forward an optional $query, and updates docs examples to pass showInternalDatabaseSizes: true and sizeFormat: 'human'.

Changes

Stats API v1.44.0 Feature Support

Layer / File(s) Summary
Data contracts for flexible size formats and internal database details
src/Contracts/Stats.php, src/Contracts/IndexStats.php
Stats and IndexStats now accept and expose database sizes as int|string. IndexStats adds an optional internalDatabaseSizes constructor parameter and getInternalDatabaseSizes() getter. fromArray() factories accept the widened input shapes.
Endpoint methods accept and forward stats query parameters
src/Endpoints/Stats.php, src/Endpoints/Delegates/HandlesSystem.php, src/Endpoints/Indexes.php
Added Stats::show(array $query = []). HandlesSystem::stats() and Indexes::stats() now accept array $query = [] and forward it to the underlying HTTP GET for /stats.
Documentation examples demonstrating new stats parameters
.code-samples.meilisearch.yaml
Updated get_index_stats_1 and get_indexes_stats_1 examples to pass showInternalDatabaseSizes: true and sizeFormat: 'human' to stats calls.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 I hopped through bytes and human prose,

sizes that whisper, sizes that grow,
internal maps now out to see,
stats speak both raw and friendly—tee-hee! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly summarizes the main change: adding query parameter support for Meilisearch v1.44 stats features (showInternalDatabaseSizes and sizeFormat).
Linked Issues check ✅ Passed All objectives from issue #915 are met: query parameters are supported, contracts accept int|string types, internalDatabaseSizes is optional, and code samples are updated.
Out of Scope Changes check ✅ Passed All changes are in scope—updates to endpoints, contracts, and code samples directly address the Meilisearch v1.44 stats feature requirements with no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Comment thread src/Endpoints/Indexes.php
/**
* @param array{showInternalDatabaseSizes?: bool, sizeFormat?: 'raw'|'human'} $query
*/
public function stats(array $query = []): array

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd use request object instead

* @return int|string
*/
public function getRawDocumentDbSize(): int
public function getRawDocumentDbSize(): int|string

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Strift i'd instead tighten the return type to https://github.com/zenstruck/bytes, but not sure if team agrees on using external packages here (when i tried to implem stats command in meilisearch-bundle, i relied on this package, but the stats are not ported to v1 yet IIRC? so i didn't open a PR)
why? because then it's a consumers choice how to format to human readable format, what unit to use, etc.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is mainly used for debugging. I don't think it's worth introducing a new dependency for now. Just passing through the data should be fine

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

imho the api should have just returned a new field instead of introducing a boolean flag that just changes the response contract, but ok

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.30%. Comparing base (0078a8c) to head (0b36ce2).
⚠️ Report is 157 commits behind head on main.

Files with missing lines Patch % Lines
src/Contracts/IndexStats.php 20.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #916      +/-   ##
==========================================
- Coverage   89.78%   88.30%   -1.48%     
==========================================
  Files          59       93      +34     
  Lines        1449     1933     +484     
==========================================
+ Hits         1301     1707     +406     
- Misses        148      226      +78     

☔ View full report in Codecov by Harness.
📢 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.

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.

[Meilisearch v1.44.0] Add human-formatted sizes and detailed DB sizes in stats

3 participants