Make WordPress Core


Ignore:
Timestamp:
07/22/2022 01:22:04 PM (21 months ago)
Author:
spacedmonkey
Message:

REST API: Use wp_get_lastest_revision_id_and_total_count function in WP_REST_Posts_Controller class.

Add new function called wp_get_lastest_revision_id_and_total_count, that performs an optimized query to get the last revision and total and use it in WP_REST_Posts_Controller class.

Props Spacedmonkey, timothyblynjacobs, furi3r, peterwilsoncc.
Fixes #55857.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r53507 r53759  
    20252025
    20262026        if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) {
    2027             $revisions       = wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) );
    2028             $revisions_count = count( $revisions );
     2027            $revision        = wp_get_lastest_revision_id_and_total_count( $post->ID );
     2028            $revisions_count = ! is_wp_error( $revision ) ? $revision['count'] : 0;
    20292029
    20302030            $links['version-history'] = array(
     
    20342034
    20352035            if ( $revisions_count > 0 ) {
    2036                 $last_revision = array_shift( $revisions );
    2037 
     2036                $last_revision                = $revision['revision'];
    20382037                $links['predecessor-version'] = array(
    20392038                    'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $last_revision ),
Note: See TracChangeset for help on using the changeset viewer.