From 2d2a9c4715f8e781026187b89adbdcbeeb55c9c1 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 25 May 2021 23:40:12 +0000 Subject: [PATCH] Posts, Post Types: Speed cached `get_pages()` calls. This improves performance for sites with persistent cache backend having a lot of pages requested via the `get_pages() function, by taking advantage of `wp_cache_get_multiple()` instead of fetching each individual page from the backend cache server one by one. It also matches the behaviour of `get_pages()` when the pages are retrieved from the database. Props david.binda, hellofromTonya. Fixes #51469. git-svn-id: https://develop.svn.wordpress.org/trunk@51018 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index df0ca10695..e7fae22267 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -5784,10 +5784,13 @@ function get_pages( $args = array() ) { $cache_key = "get_pages:$key:$last_changed"; $cache = wp_cache_get( $cache_key, 'posts' ); if ( false !== $cache ) { + _prime_post_caches( $cache, false, false ); + // Convert to WP_Post instances. $pages = array_map( 'get_post', $cache ); /** This filter is documented in wp-includes/post.php */ $pages = apply_filters( 'get_pages', $pages, $parsed_args ); + return $pages; } @@ -5948,6 +5951,7 @@ function get_pages( $args = array() ) { /** This filter is documented in wp-includes/post.php */ $pages = apply_filters( 'get_pages', array(), $parsed_args ); + return $pages; } @@ -7605,7 +7609,7 @@ function _update_term_count_on_transition_post_status( $new_status, $old_status, } /** - * Adds any posts from the given IDs to the cache that do not already exist in cache + * Adds any posts from the given IDs to the cache that do not already exist in cache. * * @since 3.4.0 * @access private