Cache: Use wp_cache_*_multiple() in core functions.

Implement the `wp_cache_add_multiple`, `wp_cache_set_multiple` and `wp_cache_delete_multiple` in a number of core functions after they were introduced in [52700]

Props: spacedmonkey, adamsilverstein, flixos90, mitogh.
Fixes: #55029.


git-svn-id: https://develop.svn.wordpress.org/trunk@52707 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2022-02-11 18:50:08 +00:00
parent 5d7297d031
commit deafd1193c
8 changed files with 55 additions and 36 deletions
+12 -14
View File
@@ -3512,10 +3512,8 @@ function clean_object_term_cache( $object_ids, $object_type ) {
$taxonomies = get_object_taxonomies( $object_type );
foreach ( $object_ids as $id ) {
foreach ( $taxonomies as $taxonomy ) {
wp_cache_delete( $id, "{$taxonomy}_relationships" );
}
foreach ( $taxonomies as $taxonomy ) {
wp_cache_delete_multiple( $object_ids, "{$taxonomy}_relationships" );
}
wp_cache_delete( 'last_changed', 'terms' );
@@ -3567,18 +3565,12 @@ function clean_term_cache( $ids, $taxonomy = '', $clean_taxonomy = true ) {
foreach ( (array) $terms as $term ) {
$taxonomies[] = $term->taxonomy;
$ids[] = $term->term_id;
wp_cache_delete( $term->term_id, 'terms' );
}
wp_cache_delete_multiple( $ids, 'terms' );
$taxonomies = array_unique( $taxonomies );
} else {
wp_cache_delete_multiple( $ids, 'terms' );
$taxonomies = array( $taxonomy );
foreach ( $taxonomies as $taxonomy ) {
foreach ( $ids as $id ) {
wp_cache_delete( $id, 'terms' );
}
}
}
foreach ( $taxonomies as $taxonomy ) {
@@ -3752,11 +3744,15 @@ function update_object_term_cache( $object_ids, $object_type ) {
}
}
$cache_values = array();
foreach ( $object_terms as $id => $value ) {
foreach ( $value as $taxonomy => $terms ) {
wp_cache_add( $id, $terms, "{$taxonomy}_relationships" );
$cache_values[ $taxonomy ][ $id ] = $terms;
}
}
foreach ( $cache_values as $taxonomy => $data ) {
wp_cache_add_multiple( $data, "{$taxonomy}_relationships" );
}
}
/**
@@ -3768,6 +3764,7 @@ function update_object_term_cache( $object_ids, $object_type ) {
* @param string $taxonomy Not used.
*/
function update_term_cache( $terms, $taxonomy = '' ) {
$data = array();
foreach ( (array) $terms as $term ) {
// Create a copy in case the array was passed by reference.
$_term = clone $term;
@@ -3775,8 +3772,9 @@ function update_term_cache( $terms, $taxonomy = '' ) {
// Object ID should not be cached.
unset( $_term->object_id );
wp_cache_add( $term->term_id, $_term, 'terms' );
$data[ $term->term_id ] = $_term;
}
wp_cache_add_multiple( $data, 'terms' );
}
//