Make WordPress Core


Ignore:
Timestamp:
10/03/2023 02:59:22 PM (10 months ago)
Author:
spacedmonkey
Message:

Query: Improve caching behavior for WP_Query when retrieving id=>parent fields

In [53941], the addition of query caching to WP_Query brought about an unintended issue when querying for fields equal to id=>parent. Specifically, on websites with object caching enabled and a substantial number of pages, the second run of this query triggered the _prime_post_caches function for id=>parent. This led to the unnecessary priming of post, meta, and term caches, even when only id and parent information were requested.

This commit addresses this issue by introducing a new function, _prime_post_parents_caches, which primes a dedicated cache for post parents. This cache is primed during the initial query execution. Subsequently, the wp_cache_get_multiple function is employed to retrieve all post parent data in a single object cache request, optimizing performance.

Additionally, this commit extends the coverage of existing unit tests to ensure the reliability of the changes.

Props kevinfodness, joemcgill, peterwilsoncc, LinSoftware, thekt12, spacedmonkey.
Fixes #59188

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r56753 r56763  
    71707170
    71717171    foreach ( $cache_values as $id => $value ) {
    7172         if ( ! $value ) {
     7172        if ( false === $value ) {
    71737173            $non_cached_ids[] = (int) $id;
    71747174        }
Note: See TracChangeset for help on using the changeset viewer.