Allow term meta lazy-loading to be selectively disabled in WP_Query.

The process of lazy-loading can be resource intensive for object that have
terms in large numbers of taxonomies and are running a persistent object cache.
This new parameter allows the feature to be disabled in these cases.

Props DBrumbaugh10Up.
See #36953.

git-svn-id: https://develop.svn.wordpress.org/trunk@37589 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2016-05-28 03:09:09 +00:00
parent 13350c95e4
commit c96858b0f2
2 changed files with 65 additions and 2 deletions
+10 -2
View File
@@ -1468,7 +1468,7 @@ class WP_Query {
* @since 4.5.0 Removed the `$comments_popup` parameter.
* Introduced the `$comment_status` and `$ping_status` parameters.
* Introduced `RAND(x)` syntax for `$orderby`, which allows an integer seed value to random sorts.
* @since 4.6.0 Added 'post_name__in' support for `$orderby`.
* @since 4.6.0 Added 'post_name__in' support for `$orderby`. Introduced `$lazy_load_term_meta`.
* @access public
*
* @param string|array $query {
@@ -1567,6 +1567,10 @@ class WP_Query {
* @type string $title Post title.
* @type bool $update_post_meta_cache Whether to update the post meta cache. Default true.
* @type bool $update_post_term_cache Whether to update the post term cache. Default true.
* @type bool $lazy_load_term_meta Whether to lazy-load term meta. Setting to false will
* disable cache priming for term meta, so that each
* get_term_meta() call will hit the database.
* Defaults to the value of `$update_post_term_cache`.
* @type int $w The week number of the year. Default empty. Accepts numbers 0-53.
* @type int $year The four-digit year. Default empty. Accepts any four-digit year.
* }
@@ -2545,6 +2549,10 @@ class WP_Query {
if ( !isset($q['update_post_term_cache']) )
$q['update_post_term_cache'] = true;
if ( ! isset( $q['lazy_load_term_meta'] ) ) {
$q['lazy_load_term_meta'] = $q['update_post_term_cache'];
}
if ( !isset($q['update_post_meta_cache']) )
$q['update_post_meta_cache'] = true;
@@ -3782,7 +3790,7 @@ class WP_Query {
$this->posts = array();
}
if ( $q['update_post_term_cache'] ) {
if ( $q['lazy_load_term_meta'] ) {
wp_queue_posts_for_term_meta_lazyload( $this->posts );
}