[wp-trac] [WordPress Trac] #51469: Use `_prime_post_caches` for speeding up cached `get_pages` call
WordPress Trac
noreply at wordpress.org
Wed Oct 7 17:08:41 UTC 2020
#51469: Use `_prime_post_caches` for speeding up cached `get_pages` call
-------------------------------+-----------------------------
Reporter: david.binda | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version:
Severity: normal | Keywords:
Focuses: performance |
-------------------------------+-----------------------------
The `get_pages` function uses a cache containing ID of pages matching
params of a [https://core.trac.wordpress.org/browser/trunk/src/wp-
includes/post.php?rev=49086#L5683 previous call].
The IDs are, on a subsequent call with the same params, inflated using the
[https://core.trac.wordpress.org/browser/trunk/src/wp-
includes/post.php?rev=49086#L5487 get_post function call]. This works well
in terms of the same request, as all the pages were previously added to
[https://core.trac.wordpress.org/browser/trunk/src/wp-
includes/post.php?rev=49086#L5660 the in-memory cache].
However, on a subsequent request, when the cache is hit, there are likely
no pages already in the in-memory cache, and those need to be fetched from
the backend cache server, one by one.
With the new `wp_cache_get_multiple`, sites with persistent cache backend
could improve the speed in such cases, in case the code used the
`_prime_post_caches` (which internally uses the `_get_non_cached_ids`
function, which is taking advantage of the mentioned
`wp_cache_get_multiple`).
But also sites without a persistent cache backend could benefit from the
bulk SQL query constructed by the `_prime_post_caches` function, instead
of fetching each page via individual SQL query.
The performance gains should be most noticeable in case a site has a lot
of pages which are being requested via `get_pages` function.
IMHO, a `_prime_post_caches( $cache, false, false );` should be used to
match the behaviour of the `get_pages` function
[https://core.trac.wordpress.org/browser/trunk/src/wp-
includes/post.php?rev=49086#L5660 when the pages are obtained from the
database] (thus, no post meta, nor taxonomies priming).
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51469>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list