Make WordPress Core


Ignore:
Timestamp:
04/21/2023 09:22:04 AM (21 months ago)
Author:
spacedmonkey
Message:

Taxonomy: Always lazily load term meta.

In [34529] introduced lazy loading of term meta. However, this was only in the context of WP_Query. Other parts of the codebase, like WP_Term_Query did not lazily load term meta. In this change, calls to update_termmeta_cache are now replaced with wp_lazyload_term_meta, that instead of priming term meta caches, just adds them to the queue to be primed it ever called. This results in far less database queries, as there a number of places where term meta is being primed unnecessarily and never used. Adding everything to the term meta queue, also means that if term meta is used, that is all loaded in a single database / cache call.

Props spacedmonkey, mukesh27, peterwilsoncc.
Fixes #57645.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r55591 r55671  
    305305
    306306        update_menu_item_cache( $query_result );
     307        get_term_meta( $term_id );
    307308
    308309        $args = $action->get_args();
     
    384385        $start_num_queries = get_num_queries();
    385386        wp_get_nav_menu_items( $this->menu_id );
     387        get_term_meta( $term_ids[0] );
    386388        $queries_made = get_num_queries() - $start_num_queries;
    387389        $this->assertSame( 6, $queries_made, 'Only does 6 database queries when running wp_get_nav_menu_items.' );
    388390
    389         $args = $action_terms->get_args();
    390         $last = end( $args );
    391         $this->assertSameSets( $term_ids, $last[1], '_prime_term_caches() was not executed.' );
     391        $args       = $action_terms->get_args();
     392        $first      = reset( $args );
     393        $term_ids[] = $this->menu_id;
     394        $this->assertSameSets( $term_ids, $first[1], '_prime_term_caches() was not executed.' );
    392395
    393396        $args = $action_posts->get_args();
Note: See TracChangeset for help on using the changeset viewer.