From 0fce77da25bf780ced29b67a916bab788182f32f Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 12 Oct 2017 14:59:47 +0000 Subject: [PATCH] Invalidate comment query cache when modifying comment meta. Comment queries are sensitive to comment meta due to the `meta_query` parameter, so the cache must be invalidated when comment meta is changed, added, or deleted. Props spacedmonkey. See #40669. Built from https://develop.svn.wordpress.org/trunk@41848 git-svn-id: http://core.svn.wordpress.org/trunk@41682 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 18 +++++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index c015fea4f2..9054e1acee 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -423,7 +423,11 @@ function get_comment_count( $post_id = 0 ) { * @return int|bool Meta ID on success, false on failure. */ function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false) { - return add_metadata('comment', $comment_id, $meta_key, $meta_value, $unique); + $added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique ); + if ( $added ) { + wp_cache_set( 'last_changed', microtime(), 'comment' ); + } + return $added; } /** @@ -442,7 +446,11 @@ function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false) * @return bool True on success, false on failure. */ function delete_comment_meta($comment_id, $meta_key, $meta_value = '') { - return delete_metadata('comment', $comment_id, $meta_key, $meta_value); + $deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value ); + if ( $deleted ) { + wp_cache_set( 'last_changed', microtime(), 'comment' ); + } + return $deleted; } /** @@ -479,7 +487,11 @@ function get_comment_meta($comment_id, $key = '', $single = false) { * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. */ function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = '') { - return update_metadata('comment', $comment_id, $meta_key, $meta_value, $prev_value); + $updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value ); + if ( $updated ) { + wp_cache_set( 'last_changed', microtime(), 'comment' ); + } + return $updated; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 13ff4a66d2..6d545f3877 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-beta2-41847'; +$wp_version = '4.9-beta2-41848'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.