Make WordPress Core

Changeset 55035


Ignore:
Timestamp:
01/06/2023 10:34:00 AM (18 months ago)
Author:
spacedmonkey
Message:

Query: Stop priming posts twice in WP_Query.

Part revert of [54352]. In cases where queries are not split, then it results in priming posts that are already loaded resulting in a superfluous database query.

Props spacedmonkey, flixos90, peterwilsoncc.
Fixes #57373.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-query.php

    r54962 r55035  
    34773477
    34783478            if ( $q['cache_results'] ) {
    3479                 $post_ids = wp_list_pluck( $this->posts, 'ID' );
    3480                 _prime_post_caches( $post_ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
     3479                update_post_caches( $this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
    34813480            }
    34823481
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r54410 r55035  
    299299        wp_get_nav_menu_items( $this->menu_id );
    300300        $queries_made = get_num_queries() - $start_num_queries;
    301         $this->assertSame( 7, $queries_made, 'Only does 7 database queries when running wp_get_nav_menu_items.' );
     301        $this->assertSame( 6, $queries_made, 'Only does 6 database queries when running wp_get_nav_menu_items.' );
    302302
    303303        $args = $action->get_args();
     
    340340        wp_get_nav_menu_items( $this->menu_id );
    341341        $queries_made = get_num_queries() - $start_num_queries;
    342         $this->assertSame( 7, $queries_made, 'Only does 7 database queries when running wp_get_nav_menu_items.' );
     342        $this->assertSame( 6, $queries_made, 'Only does 6 database queries when running wp_get_nav_menu_items.' );
    343343
    344344        $args = $action_terms->get_args();
Note: See TracChangeset for help on using the changeset viewer.