From 65c83c659a5f9e3b68ecae157bbcc3c0a1ad3ad5 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 28 Sep 2012 12:47:31 +0000 Subject: [PATCH] Invalidate the WP_Comment_Query:query() cache when comments are added. Switch last_changed to a counter incremented via wp_cache_incr(). fixes #22024 git-svn-id: http://core.svn.wordpress.org/trunk@22080 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 4dea56fcf8..d0223b7666 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -249,16 +249,13 @@ class WP_Comment_Query { // $args can be whatever, only use the args defined in defaults to compute the key $key = md5( serialize( compact(array_keys($defaults)) ) ); - $last_changed = wp_cache_get('last_changed', 'comment'); - if ( ! $last_changed ) { - $last_changed = time(); - wp_cache_set('last_changed', $last_changed, 'comment'); - } + $last_changed = wp_cache_get( 'last_changed', 'comment' ); + if ( ! $last_changed ) + $last_changed = wp_cache_set( 'last_changed', 1, 'comment' ); $cache_key = "get_comments:$key:$last_changed"; - if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) { + if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) return $cache; - } $post_id = absint($post_id); @@ -1293,6 +1290,8 @@ function wp_insert_comment($commentdata) { $comment = get_comment($id); do_action('wp_insert_comment', $id, $comment); + wp_cache_incr( 'last_changed', 1, 'comment' ); + return $id; } @@ -1964,7 +1963,7 @@ function clean_comment_cache($ids) { foreach ( (array) $ids as $id ) wp_cache_delete($id, 'comment'); - wp_cache_set('last_changed', time(), 'comment'); + wp_cache_incr( 'last_changed', 1, 'comment' ); } /**