Skip to content

Load comments and users in chunks in wp comment list and wp user list - #666

Open
swissspidy wants to merge 1 commit into
claude/post-list-chunkedfrom
claude/list-chunked
Open

swissspidy wants to merge 1 commit into
claude/post-list-chunkedfrom
claude/list-chunked

Conversation

@swissspidy

@swissspidy swissspidy commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Stacked on #663. It applies the same approach as wp post list to comments and users. Please merge #663 first; this PR's base will then switch to main.

Changes

  • Chunked loading: wp comment list and wp user list query the IDs of all matching items first, then load the objects a chunk at a time and clear the object cache after each chunk. Together with Stream CSV and JSON output when items are given as an iterator wp-cli#6420 (CSV and JSON streamed from iterators), memory no longer grows with the number of items.
  • Cache kept when needed: if a displayed field is read through the object cache, such as user meta or a comment's post title, the cache isn't cleared.
  • url only when displayed: the url field of comments, users and terms is now only computed when it's requested. For comments it was about 40% of the time.
  • Shared helpers: the chunk size and the cache helper move from Post_Command to CommandWithDBObject.

--format=ids and --format=count keep their existing path.

Results

--format=csv Before After
wp comment list, 100k comments 630 MB ~110 MB
wp user list, 50k users 790 MB ~140 MB

Run time drops by about 40% for both. The output is identical to main.

Tests

  • New scenarios in features/comment.feature and features/user.feature. Each lists more items than one chunk (1,200 comments, 600 users) and checks:
    • the order matches --format=ids,
    • the CSV row count,
    • the url field for comments, and a user meta field for users.
  • Feature suites: comment.feature, user.feature, term.feature and post.feature pass locally on MariaDB and SQLite.
  • Static checks: PHPCS and PHPStan are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01D26yjkN2BiqCXT6p6o1WqS

Summary by CodeRabbit

  • Improvements
    • Comment and user listings now handle large result sets in batches, helping maintain reliable output for extensive lists.
    • CSV and ID output preserves the expected ordering and values for large comment and user lists.
    • Comment, user, and term URLs are included when requested by the selected output fields.

…ist`

Like `wp post list`, query the IDs of all matching comments or users
first, then load the objects a chunk at a time and clear the object
cache after each chunk. Combined with the formatter streaming CSV and
JSON output for iterators, the memory use no longer grows with the
number of items. If a displayed field is read through the object cache,
like user meta or the post title of a comment, the cache is kept.

Also only compute the `url` field of comments, users and terms when it
is displayed. For comments it took about 40% of the time.

The chunk size and the cache helper move to CommandWithDBObject.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D26yjkN2BiqCXT6p6o1WqS
Copilot AI balanced review requested due to automatic review settings October 6, 2026 16:28
@swissspidy
swissspidy requested a review from a team as a code owner October 6, 2026 16:28

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 177189cf-548e-45ac-b8db-cc18f27b81df
📥 Commits

Reviewing files that changed from the base of the PR and between c3563e6 and 5bd5d04.

📒 Files selected for processing (7)
  • features/comment.feature
  • features/user.feature
  • src/Comment_Command.php
  • src/Post_Command.php
  • src/Term_Command.php
  • src/User_Command.php
  • src/WP_CLI/CommandWithDBObject.php
💤 Files with no reviewable changes (1)
  • src/Post_Command.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Comment and user listings now load eligible results in chunks. Comment, user, and term listings add URLs only when requested. Added feature scenarios check large comment and user listings and CSV output.

Changes

Entity listing updates

Layer / File(s) Summary
Shared chunk and cache support
src/WP_CLI/CommandWithDBObject.php, src/Post_Command.php
CommandWithDBObject defines a chunk size of 500 and a runtime cache-clearing helper. Post_Command removes its previous chunk-size constant and cache helper.
Comment listing and conditional URLs
src/Comment_Command.php, src/Term_Command.php, features/comment.feature
Non-hierarchical comment listings other than count and ids load results in chunks and preserve ID order. Comment and term URLs are added only when requested. The comment scenario checks large listings and CSV output.
User listing in chunks
src/User_Command.php, features/user.feature
User listings other than count and ids load results in chunks and preserve ID order. URLs are added only when requested. The user scenario checks large listings and CSV output.

Priority: ➖ Normal

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

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant Comment_Command
  participant Database
  participant Formatter
  participant RuntimeCache
  CLI->>Comment_Command: request comment listing
  Comment_Command->>Database: retrieve matching IDs
  Comment_Command->>Database: load comment batches
  Comment_Command->>Formatter: yield comments in ID order
  Comment_Command->>RuntimeCache: clear cache when requested fields permit
Loading
sequenceDiagram
  participant CLI
  participant User_Command
  participant Database
  participant Formatter
  participant RuntimeCache
  CLI->>User_Command: request user listing
  User_Command->>Database: retrieve matching IDs
  User_Command->>Database: load user batches
  User_Command->>Formatter: yield users in ID order
  User_Command->>RuntimeCache: clear cache unless requested fields may need user meta
Loading

Suggested reviewers: schlessera

Merge Risk: ⚪ Minimal · up to 5bd5d

The chunked listing changes appear mergeable after normal checks; no concrete listing regression remains identified.

🚥 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 and concisely identifies the main change: chunked loading for comment and user list commands.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (2 skipped: 2 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions github-actions Bot added command:comment-list Related to 'comment list' command command:user-list Related to 'user list' command labels Oct 6, 2026
@swissspidy
swissspidy added this pull request to stack #667 October 6, 2026 16:45
@codecov

codecov Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.02326% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Comment_Command.php 93.18% 3 Missing ⚠️
src/WP_CLI/CommandWithDBObject.php 60.00% 2 Missing ⚠️
src/User_Command.php 97.05% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:comment-list Related to 'comment list' command command:user-list Related to 'user list' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants