Skip to content

REST API: Query autosaves directly for every autosaves collection request. - #66

Open
whyisjake wants to merge 2 commits into
adamsilverstein:ticket/62057from
whyisjake:62057/stacked-on-7555
Open

whyisjake wants to merge 2 commits into
adamsilverstein:ticket/62057from
whyisjake:62057/stacked-on-7555

Conversation

@whyisjake

Copy link
Copy Markdown

Stacked on WordPress#7555. Trac ticket: https://core.trac.wordpress.org/ticket/62057

This is the same change as 62057.6.patch on the ticket, as a single commit on top of ticket/62057 so it can be reviewed or merged as a delta.

What changes

  • One query path. The direct autosave query runs for every request; author only adds author__in. Without author, the collection previously still loaded every revision through wp_get_post_revisions(), which is what core's editor preload requests today.
  • post_name__in instead of name, so the query isn't singular.
  • suppress_filters set to true, preserving the isolation the old get_posts() path had. With false, a global posts_where/posts_orderby filter applied to the author lookup.
  • The per-author dedupe applies to both paths, so scoped and unscoped responses agree.
  • @since 7.3.0 on get_items() and get_collection_params(); stale per_page wording removed from a test docblock.
  • New test test_get_items_is_isolated_from_query_filters (unscoped and author scoped).

Before / after

Measured at svn r64336. Retained memory is the memory_get_usage() delta across one rest_do_request() with caches flushed, one PHPUnit process per row. Each post has 3 autosaves plus N ordinary revisions, about 200KB each. Single run per row.

Ordinary revisions Request WordPress#7555 This PR
0 without author 2.73 MB 2.73 MB
50 without author 12.54 MB 2.92 MB
200 without author 41.41 MB 2.92 MB
200 with author 2.14 MB 2.13 MB

test_get_items_is_isolated_from_query_filters against each controller:

Data set WordPress#7555 This PR
unscoped pass pass
author scoped fail (posts_where ran) pass

Testing

Run in the svn checkout at r64336 with WordPress#7555 plus this commit applied:

  • phpunit --filter WP_Test_REST_Autosaves_Controller: OK (55 tests, 275 assertions)
  • phpcs on both changed files: clean

Earlier, with 62057.6.patch applied: tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php OK (36 tests, 2 skipped) and WP_Test_REST_Schema_Initialization OK (2 tests).

AI use

AI assistance: Yes. Tool(s): Claude Code. Used for: reviewing WordPress#7555, writing this change and its test, running the tests and memory measurements above, and drafting this description.

I have reviewed every line and can speak to the approach.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

🤖 Generated with Claude Code

…uest.

Without `author`, the collection still loaded every revision of the parent
through wp_get_post_revisions() and filtered out the autosaves, so memory
grew with revision count, including for the editor's preload. Run the
direct autosave query for every request and have `author` only add
`author__in`.

Match on `post_name__in` rather than `name`, which made the query
singular, and suppress query filters to keep the isolation the
get_posts() path had. Apply the per-author dedupe to both paths, and
update the `@since` tags to 7.3.0.

See #62057.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 45cf2c6d-244f-477c-8df6-b1904052a48e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · 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.

@whyisjake
whyisjake marked this pull request as ready for review October 20, 2026 17:37
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props whyisjake.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Add the parameter, return and data provider types suggested in review,
type the REST response data and created IDs, and use array_first() for
the newest revision. Assert that wp_update_post() returns the post ID
and that the newest revision is the ordinary one, not an autosave.

Also drop a blank line inside the per-author dedupe loop.

See #62057.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

1 participant