WordPress.org

Make WordPress Core

Opened 8 weeks ago

Last modified 5 days ago

#51469 reviewing enhancement

Use `_prime_post_caches` for speeding up cached `get_pages` call

Reported by: david.binda Owned by: SergeyBiryukov
Milestone: 5.7 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: performance Cc:

Description

The get_pages function uses a cache containing ID of pages matching params of a previous call.

The IDs are, on a subsequent call with the same params, inflated using the get_post function call. This works well in terms of the same request, as all the pages were previously added to 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 when the pages are obtained from the database (thus, no post meta, nor taxonomies priming).

Attachments (1)

51469.diff (527 bytes) - added by david.binda 8 weeks ago.

Download all attachments as: .zip

Change History (3)

@david.binda
8 weeks ago

#1 @david.binda
8 weeks ago

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.

This does not apply, as the initial wp_cache_get on a subsequent request on a site without persistent object cache backend would not get anything.

But, IHMO, the rest of the report still applies for sites with persistent object cache backend :)

#2 @SergeyBiryukov
5 days ago

  • Milestone changed from Awaiting Review to 5.7
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing
Note: See TracTickets for help on using tickets.