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.

git-svn-id: https://develop.svn.wordpress.org/trunk@55671 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2023-04-21 09:22:04 +00:00
parent 70054b77af
commit 2c6bf77a9e
10 changed files with 86 additions and 24 deletions
+10 -3
View File
@@ -195,9 +195,7 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase {
$this->_restore_hooks();
wp_set_current_user( 0 );
$lazyloader = wp_metadata_lazyloader();
$lazyloader->reset_queue( 'term' );
$lazyloader->reset_queue( 'comment' );
$this->reset_lazyload_queue();
}
/**
@@ -276,6 +274,15 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase {
}
/**
* Reset the lazy load meta queue.
*/
protected function reset_lazyload_queue() {
$lazyloader = wp_metadata_lazyloader();
$lazyloader->reset_queue( 'term' );
$lazyloader->reset_queue( 'comment' );
}
/**
* Unregisters existing post types and register defaults.
*