Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 65c83c659a5f9e3b68ecae157bbcc3c0a1ad3ad5 1 parent 996268f
Ryan Boren authored
Showing with 7 additions and 8 deletions.
  1. +7 −8 wp-includes/comment.php
View
15 wp-includes/comment.php
@@ -249,16 +249,13 @@ function query( $query_vars ) {
// $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' );
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.