Skip to content

Conversation

@waviaei
Copy link

@waviaei waviaei commented Aug 9, 2024

Set update_post_meta_cache and update_post_term_cache to false, for to use as default $args to be passed to get_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.

@github-actions
Copy link

github-actions bot commented Aug 9, 2024

Hi @waviaei! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

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 WordPress Project

@github-actions
Copy link

github-actions bot commented Aug 9, 2024

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 toru.

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

@github-actions
Copy link

github-actions bot commented Aug 9, 2024

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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' ) );
Copy link
Contributor

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

Copy link
Author

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.

Comment on lines +671 to +672
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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.

Screenshot 2024-09-12 at 3 12 31 PM

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.

2 participants