From ab0feb8b44eca9648f00c74f7932b794307f9ce2 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 6 Dec 2022 19:59:45 +0000 Subject: [PATCH] Tests: Change the `wp_cache_get_multiple` function to get cache keys in a single request. Follow up from [54423]. Change the `wp_cache_get_multiple` function to call the `getMulti` method in the object cache object, to get cache keys in a single call to memcache. This speeds up test by loading caches faster. Props spacedmonkey, SergeyBiryukov. See #54864. git-svn-id: https://develop.svn.wordpress.org/trunk@54942 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/object-cache.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/includes/object-cache.php b/tests/phpunit/includes/object-cache.php index c1fe9755a6..c9e51e6d4b 100644 --- a/tests/phpunit/includes/object-cache.php +++ b/tests/phpunit/includes/object-cache.php @@ -323,7 +323,12 @@ function wp_cache_flush( $delay = 0 ) { * @return bool True if the feature is supported, false otherwise. */ function wp_cache_supports( $feature ) { - return false; + switch ( $feature ) { + case 'get_multiple': + return true; + default: + return false; + } } /** @@ -482,6 +487,10 @@ function wp_cache_get_multi_by_key( $server_key, $keys, $groups = '', &$cas_toke */ function wp_cache_get_multiple( $keys, $group = '', $force = false ) { global $wp_object_cache; + + // Prime multiple keys in a single Memcached call. + $wp_object_cache->getMulti( $keys, $group ); + return $wp_object_cache->getMultiple( $keys, $group, $force ); } @@ -2161,6 +2170,7 @@ class WP_Object_Cache { if ( ! is_array( $keys ) ) { $keys = (array) $keys; } + $keys = array_values( $keys ); // If we have equal numbers of keys and groups, merge $keys[n] and $group[n]. if ( count( $keys ) === count( $groups ) ) {