Make WordPress Core


Ignore:
Timestamp:
10/21/2025 03:31:55 AM (11 months ago)
Author:
peterwilsoncc
Message:

REST API: Improve performance of X-WP-Total/X-WP-TotalPages queries.

Improve the performance of fallback queries to determine the total number of objects available on various REST endpoints for out of bounds queries.

The database queries are modified to return the minimum amount of data required for determining the count and bypass priming of meta a term caches where appropriate.

Props adamsilverstein, joehoyle, johnbillion, jorbin, kadamwhite, spacedmonkey, sukhendu2002, westonruter.
Fixes #62801.

File:
1 edited

Legend:

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

    r60987 r61002  
    324324
    325325                if ( $total_comments < 1 ) {
    326                         // Out-of-bounds, run the query again without LIMIT for total count.
     326                        // Out-of-bounds, run the query without pagination/offset to get the total count.
    327327                        unset( $prepared_args['number'], $prepared_args['offset'] );
    328328
    329                         $query                    = new WP_Comment_Query();
    330                         $prepared_args['count']   = true;
    331                         $prepared_args['orderby'] = 'none';
     329                        $query                                      = new WP_Comment_Query();
     330                        $prepared_args['count']                     = true;
     331                        $prepared_args['orderby']                   = 'none';
     332                        $prepared_args['update_comment_meta_cache'] = false;
    332333
    333334                        $total_comments = $query->query( $prepared_args );
Note: See TracChangeset for help on using the changeset viewer.