Make WordPress Core


Ignore:
Timestamp:
04/21/2023 09:22:04 AM (20 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/includes/abstract-testcase.php

    r55657 r55671  
    196196        wp_set_current_user( 0 );
    197197
    198         $lazyloader = wp_metadata_lazyloader();
    199         $lazyloader->reset_queue( 'term' );
    200         $lazyloader->reset_queue( 'comment' );
     198        $this->reset_lazyload_queue();
    201199    }
    202200
     
    275273        }
    276274
     275    }
     276
     277    /**
     278     * Reset the lazy load meta queue.
     279     */
     280    protected function reset_lazyload_queue() {
     281        $lazyloader = wp_metadata_lazyloader();
     282        $lazyloader->reset_queue( 'term' );
     283        $lazyloader->reset_queue( 'comment' );
    277284    }
    278285
Note: See TracChangeset for help on using the changeset viewer.