From 3e9c88d75a1d86abd70af95e6c2f1f8ac6a3cfe1 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 12 Feb 2016 02:47:26 +0000 Subject: [PATCH] In `delete_metadata()`, only invalidate cache for affected objects. The `$delete_all` flag in `delete_metadata()` triggers cache invalidation for multiple objects. Previously, invalidation took place for all objects matching the `$meta_key` parameter, regardless of whether `$meta_value` was also set. This resulted in overly aggressive invalidation. Props rahal.aboulfeth. Fixes #35797. Built from https://develop.svn.wordpress.org/trunk@36511 git-svn-id: http://core.svn.wordpress.org/trunk@36478 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/meta.php | 10 ++++++++-- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-includes/meta.php b/wp-includes/meta.php index a3cbed0b99..86cc324d4e 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -363,8 +363,14 @@ function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $d if ( !count( $meta_ids ) ) return false; - if ( $delete_all ) - $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) ); + if ( $delete_all ) { + $value_clause = ''; + if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value ) { + $value_clause = $wpdb->prepare( " AND meta_value = %s", $meta_value ); + } + + $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s $value_clause", $meta_key ) ); + } /** * Fires immediately before deleting metadata of a specific type. diff --git a/wp-includes/version.php b/wp-includes/version.php index 7ff21ee894..88f4904a2f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36510'; +$wp_version = '4.5-alpha-36511'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.