Skip to content

Add transients size check - #217

Open
ekamran wants to merge 5 commits into
wp-cli:mainfrom
ekamran:fix/transients-size
Open

Add transients size check#217
ekamran wants to merge 5 commits into
wp-cli:mainfrom
ekamran:fix/transients-size

Conversation

@ekamran

@ekamran ekamran commented Aug 3, 2026

Copy link
Copy Markdown

Summary

Adds a separate transients-size check for detecting large autoloaded transients.

Non-expiring transients are autoloaded by WordPress, but they are intentionally excluded from the existing autoload-options-size check. This new check reports them separately, as suggested in the issue.

The check is included in the default Doctor configuration and uses the same configurable 900 KB threshold as the existing autoloaded options check.

Implementation

The check uses wp option list with the transients, autoload and total_bytes options.

The required filtering was corrected in wp-cli/entity-command#620 and released in Entity Command v2.8.12. The minimum dependency has therefore been updated to ^2.8.12.

Testing

  • Composer validation
  • PHP lint
  • PHPCS
  • PHPStan
  • PHPUnit
  • Focused Behat scenarios with SQLite and MySQL 8
  • Full Doctor Command Behat suite with SQLite
  • Manual testing against WordPress with MySQL 8

Fixes #150

Summary by CodeRabbit

  • New Features

    • Added a transients-size check to the default Doctor configuration.
    • Reports whether autoloaded transient data exceeds the recommended 900 KB threshold, with readable sizes and configurable limits.
    • Excludes expiring transients from the measurement.
    • Added the check to Doctor documentation and available check listings.
  • Bug Fixes

    • Clarified autoloaded options size messages to accurately describe threshold comparisons.
  • Tests

    • Added coverage for success, warning, exclusions, custom thresholds, and size formatting scenarios.

@ekamran
ekamran requested a review from a team as a code owner August 3, 2026 20:16
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Hello! 👋

Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project.

Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Here are some useful Composer commands to get you started:

  • composer install: Install dependencies.
  • composer test: Run the full test suite.
  • composer phpcs: Check for code style violations.
  • composer phpcbf: Automatically fix code style violations.
  • composer phpunit: Run unit tests.
  • composer behat: Run behavior-driven tests.

To run a single Behat test, you can use the following command:

# Run all tests in a single file
composer behat features/some-feature.feature

# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123

You can find a list of all available Behat steps in our handbook.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 45d8aa95-06cb-408b-8ae9-94eb2aa4e0d6

📥 Commits

Reviewing files that changed from the base of the PR and between efb9de8 and 02706d7.

📒 Files selected for processing (4)
  • features/check-autoload-options-size.feature
  • features/check-transients-size.feature
  • src/Check/Autoload_Options_Size.php
  • src/Check/Transients_Size.php
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Check/Transients_Size.php
  • src/Check/Autoload_Options_Size.php

📝 Walkthrough

Walkthrough

The pull request adds a transients-size doctor check. It measures autoloaded transient sizes, applies configurable thresholds, registers the check, updates command listings, and adds end-to-end coverage. It also centralizes byte formatting and changes autoload-size message wording.

Changes

Transients size check

Layer / File(s) Summary
Implement transient size measurement
src/Check/Transients_Size.php, src/Check.php, composer.json
Adds the Transients_Size check, shared byte formatting, and the updated entity-command constraint.
Register and document the check
doctor.yml, src/Command.php
Adds transients-size to the default configuration and documented check listings.
Update autoload size messaging
src/Check/Autoload_Options_Size.php, features/check-autoload-options-size.feature
Changes success messages to “does not exceed threshold” and removes the private formatter while retaining its call.
Validate thresholds and exclusions
features/check-transients-size.feature, features/check.feature
Adds coverage for descriptions, boundary results, warnings, exclusions, custom thresholds, byte formatting, and default-list behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Transients_Size
  participant WP_CLI_option_list
  participant WordPress_options
  Transients_Size->>WP_CLI_option_list: Request autoloaded transient sizes
  WP_CLI_option_list->>WordPress_options: Query transient options
  WordPress_options-->>WP_CLI_option_list: Return option sizes
  WP_CLI_option_list-->>Transients_Size: Return total bytes
  Transients_Size-->>Transients_Size: Compare total with threshold
Loading

Suggested reviewers: brianhenryie, ernilambar, janw-me

🚥 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 title clearly identifies the primary change: adding the transients-size check.
Linked Issues check ✅ Passed The PR adds a dedicated check for non-expiring autoloaded transients and includes it in defaults, documentation, and end-to-end coverage [#150].
Out of Scope Changes check ✅ Passed All changes support the transients-size check, shared formatting, dependency support, documentation, configuration, or related tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new transients-size Doctor check to surface large autoloaded non-expiring transients separately from the existing autoloaded options size check, aligning with the behavior discussed in #150 and relying on updated filtering in wp-cli/entity-command (>= 2.8.12).

Changes:

  • Introduces WP_CLI\Doctor\Check\Transients_Size and registers it in the default doctor.yml configuration.
  • Updates CLI documentation/examples to include transients-size in the listed checks.
  • Adds new Behat coverage for transients-size scenarios and updates the default-check listing test; bumps the minimum wp-cli/entity-command dependency to ^2.8.12 || ^3.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Command.php Updates documented “list checks” examples to include the new transients-size check.
src/Check/Transients_Size.php Implements the new check by measuring total bytes of autoloaded transients via wp option list.
features/check.feature Extends the “List all default checks” scenario to expect transients-size.
features/check-transients-size.feature Adds Behat scenarios covering success/warning behavior and custom threshold configuration.
doctor.yml Registers transients-size in the default Doctor configuration.
composer.json Raises wp-cli/entity-command minimum to ^2.8.12 to depend on corrected transient filtering behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Check/Transients_Size.php Outdated
Comment thread src/Check/Transients_Size.php

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
features/check-transients-size.feature (1)

1-24: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add an exact-threshold scenario.

The scenarios cover an empty result and a result above 900 KB. Add a case where the measured autoloaded transient size equals 900 KB. Assert the status and message so a future change from > to >= is detected.

🤖 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 `@features/check-transients-size.feature` around lines 1 - 24, Add a scenario
in the transients-size feature covering autoloaded transients measuring exactly
900 KB. Run the transients-size check and assert a success status plus the
message indicating the size is less than the 900kb threshold, ensuring equality
remains below the warning boundary rather than being treated as exceeding it.
🤖 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.

Nitpick comments:
In `@features/check-transients-size.feature`:
- Around line 1-24: Add a scenario in the transients-size feature covering
autoloaded transients measuring exactly 900 KB. Run the transients-size check
and assert a success status plus the message indicating the size is less than
the 900kb threshold, ensuring equality remains below the warning boundary rather
than being treated as exceeding it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: eeb490e2-d72c-4c63-9d1d-c9d3a131beb0

📥 Commits

Reviewing files that changed from the base of the PR and between 70ad1fd and efb9de8.

📒 Files selected for processing (4)
  • features/check-transients-size.feature
  • src/Check.php
  • src/Check/Autoload_Options_Size.php
  • src/Check/Transients_Size.php
💤 Files with no reviewable changes (2)
  • src/Check/Autoload_Options_Size.php
  • src/Check/Transients_Size.php

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.

autoload-options-size check should include autoloaded transients

2 participants