From def933ced79b8faeb4c990ef9935ed8ba6130199 Mon Sep 17 00:00:00 2001 From: Jake Spurlock Date: Tue, 16 Jun 2020 06:28:57 +0000 Subject: [PATCH] Cache API: Add `wp_cache_get_multiple()` to core functions. * `update_object_term_cache` * `update_meta_cache` * `_get_non_cached_ids` See [47938]. Fixes #50352. Props spacedmonkey, tillkruss, lukecavanagh. git-svn-id: https://develop.svn.wordpress.org/trunk@48055 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 7 ++++--- src/wp-includes/meta.php | 10 +++++----- src/wp-includes/taxonomy.php | 9 +++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 46a9db42bf..2edb6a6a11 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -6359,10 +6359,11 @@ function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pr * @return int[] Array of IDs not present in the cache. */ function _get_non_cached_ids( $object_ids, $cache_key ) { - $clean = array(); - foreach ( $object_ids as $id ) { + $clean = array(); + $cache_values = wp_cache_get_multiple( $object_ids, $cache_key ); + foreach ( $cache_values as $id => $cache_value ) { $id = (int) $id; - if ( ! wp_cache_get( $id, $cache_key ) ) { + if ( ! $cache_value ) { $clean[] = $id; } } diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php index de00456c78..c34e724db2 100644 --- a/src/wp-includes/meta.php +++ b/src/wp-includes/meta.php @@ -926,11 +926,11 @@ function update_meta_cache( $meta_type, $object_ids ) { return (bool) $check; } - $cache_key = $meta_type . '_meta'; - $ids = array(); - $cache = array(); - foreach ( $object_ids as $id ) { - $cached_object = wp_cache_get( $id, $cache_key ); + $cache_key = $meta_type . '_meta'; + $ids = array(); + $cache = array(); + $cache_values = wp_cache_get_multiple( $object_ids, $cache_key ); + foreach ( $cache_values as $id => $cached_object ) { if ( false === $cached_object ) { $ids[] = $id; } else { diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index c8f2d4efa1..b8bbc5048b 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -3410,10 +3410,11 @@ function update_object_term_cache( $object_ids, $object_type ) { $taxonomies = get_object_taxonomies( $object_type ); $ids = array(); - foreach ( (array) $object_ids as $id ) { - foreach ( $taxonomies as $taxonomy ) { - if ( false === wp_cache_get( $id, "{$taxonomy}_relationships" ) ) { - $ids[] = $id; + foreach ( $taxonomies as $taxonomy ) { + $cache_values = wp_cache_get_multiple( (array) $object_ids, "{$taxonomy}_relationships" ); + foreach ( $cache_values as $key => $value ) { + if ( false === $value ) { + $ids[] = $key; break; } }