Make WordPress Core


Ignore:
Timestamp:
04/21/2023 09:22:04 AM (3 years 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/term/meta.php

    r51568 r55671  
    117117        global $wpdb;
    118118
    119         // Clear any previous term IDs from the queue.
    120         wp_metadata_lazyloader()->reset_queue( 'term' );
    121 
    122119        $p = self::factory()->post->create( array( 'post_status' => 'publish' ) );
    123120
     
    200197            add_term_meta( $t, 'foo', 'bar' );
    201198        }
    202 
     199        $this->reset_lazyload_queue();
    203200        $q = new WP_Query(
    204201            array(
Note: See TracChangeset for help on using the changeset viewer.