Revisions: optimize performance when post has large number of revisions.

Improve speed and reduce the memory footprint when loading posts with many revisions.

* Use a direct query in `wp_get_post_autosave` to avoid loading all revisions.
* Query for IDs vs full objects in `register_and_do_post_meta_boxes`.

Props pdfernhout, johnnyb, miqrogroove, ocean90, senatorman, DBrumbaugh10Up, martijn-van-der-kooij, pavelevap, mackensen, mikeyarce, whyisjake.
Fixes #34560.



git-svn-id: https://develop.svn.wordpress.org/trunk@48422 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Adam Silverstein
2020-07-10 15:12:00 +00:00
parent 73d3e9cfd9
commit 4adb926ce8
4 changed files with 31 additions and 15 deletions
+2 -2
View File
@@ -1437,14 +1437,14 @@ function register_and_do_post_meta_boxes( $post ) {
$publish_callback_args = array( '__back_compat_meta_box' => true );
if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' !== $post->post_status ) {
$revisions = wp_get_post_revisions( $post->ID );
$revisions = wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) );
// We should aim to show the revisions meta box only when there are revisions.
if ( count( $revisions ) > 1 ) {
reset( $revisions ); // Reset pointer for key().
$publish_callback_args = array(
'revisions_count' => count( $revisions ),
'revision_id' => key( $revisions ),
'revision_id' => array_shift( $revisions ),
'__back_compat_meta_box' => true,
);
add_meta_box( 'revisionsdiv', __( 'Revisions' ), 'post_revisions_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );