Make WordPress Core


Ignore:
Timestamp:
02/11/2022 06:50:08 PM (2 years ago)
Author:
spacedmonkey
Message:

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

Implement the wp_cache_add_multiplewp_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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r52669 r52707  
    35133513    $taxonomies = get_object_taxonomies( $object_type );
    35143514
    3515     foreach ( $object_ids as $id ) {
    3516         foreach ( $taxonomies as $taxonomy ) {
    3517             wp_cache_delete( $id, "{$taxonomy}_relationships" );
    3518         }
     3515    foreach ( $taxonomies as $taxonomy ) {
     3516        wp_cache_delete_multiple( $object_ids, "{$taxonomy}_relationships" );
    35193517    }
    35203518
     
    35683566            $taxonomies[] = $term->taxonomy;
    35693567            $ids[]        = $term->term_id;
    3570             wp_cache_delete( $term->term_id, 'terms' );
    3571         }
    3572 
     3568        }
     3569        wp_cache_delete_multiple( $ids, 'terms' );
    35733570        $taxonomies = array_unique( $taxonomies );
    35743571    } else {
     3572        wp_cache_delete_multiple( $ids, 'terms' );
    35753573        $taxonomies = array( $taxonomy );
    3576 
    3577         foreach ( $taxonomies as $taxonomy ) {
    3578             foreach ( $ids as $id ) {
    3579                 wp_cache_delete( $id, 'terms' );
    3580             }
    3581         }
    35823574    }
    35833575
     
    37533745    }
    37543746
     3747    $cache_values = array();
    37553748    foreach ( $object_terms as $id => $value ) {
    37563749        foreach ( $value as $taxonomy => $terms ) {
    3757             wp_cache_add( $id, $terms, "{$taxonomy}_relationships" );
    3758         }
     3750            $cache_values[ $taxonomy ][ $id ] = $terms;
     3751        }
     3752    }
     3753    foreach ( $cache_values as $taxonomy => $data ) {
     3754        wp_cache_add_multiple( $data, "{$taxonomy}_relationships" );
    37593755    }
    37603756}
     
    37693765 */
    37703766function update_term_cache( $terms, $taxonomy = '' ) {
     3767    $data = array();
    37713768    foreach ( (array) $terms as $term ) {
    37723769        // Create a copy in case the array was passed by reference.
     
    37763773        unset( $_term->object_id );
    37773774
    3778         wp_cache_add( $term->term_id, $_term, 'terms' );
    3779     }
     3775        $data[ $term->term_id ] = $_term;
     3776    }
     3777    wp_cache_add_multiple( $data, 'terms' );
    37803778}
    37813779
Note: See TracChangeset for help on using the changeset viewer.