-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Avoid updating post meta and term cache #7171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Avoid updating post meta and term cache #7171
Conversation
|
Hi @waviaei! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Specify fields ids, and pass to wp_get_post_revisions() to improve performance.
| } | ||
|
|
||
| $revisions = wp_get_post_revisions( $post->ID ); | ||
| $revisions = wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the call to wp_is_post_autosave() later in this function, limiting the query to IDs only will cause an increase in the number of DB queries. As a POC test:
/**
* @ticket 61849
*/
public function test_wp_list_post_revisions_db_queries() {
$post = get_default_post_to_edit( 'post', true );
$post_id = $post->ID;
// Create a few revisions.
foreach ( range( 1, 5 ) as $i ) {
wp_update_post(
array(
'post_status' => 'publish',
'post_content' => 'Content ' . $i,
'ID' => $post_id,
)
);
}
// Flush the cache.
wp_cache_flush();
// Get number of queries before calling wp_list_post_revisions.
$queries = get_num_queries();
get_echo( 'wp_list_post_revisions', array( $post_id ) );
$number_of_queries = get_num_queries() - $queries;
// Expect four queries for the revisions.
$this->assertSame( 4, $number_of_queries );
}On trunk the test passes, on this branch it fails:
$ ./vendor/bin/phpunit --group 61849
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 9.6.19 by Sebastian Bergmann and contributors.
Warning: Your XML configuration validates against a deprecated schema.
Suggestion: Migrate your XML configuration using "--migrate-configuration"!
F 1 / 1 (100%)
Time: 00:00.160, Memory: 199.00 MB
There was 1 failure:
1) Tests_Post_Revisions::test_wp_list_post_revisions_db_queries
Failed asserting that 8 is identical to 4.
/vagrant/wordpress-develop/tests/phpunit/tests/post/revisions.php:48
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterwilsoncc Thank you for the POC test. I run the same test and yes, more queries here. I will look to revert the commit.
| 'update_post_meta_cache' => false, | ||
| 'update_post_term_cache' => false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For posts with footnotes enabled the footnotes meta data is included in the revisions (see src/wp-includes/blocks/footnotes.php) so I think the meta cache will need to remain primed.
You may be able to check if the post type supports footnotes.
Not priming the term cache makes sense though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterwilsoncc Footnotes - thats a good point, thanks. But still, wp_list_post_revisions() doesn't need to use any data from postmeta. I am thinking, as long as post information is primed, that is all it needs here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@waviaei Footnotes are included on the revision screen. Plugin developers can also register meta data with revisions and may choose to display that on the revisions screen too.

Set
update_post_meta_cacheandupdate_post_term_cacheto false, for to use as default$argsto be passed toget_children().Trac ticket: https://core.trac.wordpress.org/ticket/61849
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.