Make WordPress Core


Ignore:
Timestamp:
10/12/2017 02:58:58 PM (6 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

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

    r41704 r41848  
    424424 */
    425425function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false) {
    426     return add_metadata('comment', $comment_id, $meta_key, $meta_value, $unique);
     426    $added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
     427    if ( $added ) {
     428        wp_cache_set( 'last_changed', microtime(), 'comment' );
     429    }
     430    return $added;
    427431}
    428432
     
    443447 */
    444448function delete_comment_meta($comment_id, $meta_key, $meta_value = '') {
    445     return delete_metadata('comment', $comment_id, $meta_key, $meta_value);
     449    $deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
     450    if ( $deleted ) {
     451        wp_cache_set( 'last_changed', microtime(), 'comment' );
     452    }
     453    return $deleted;
    446454}
    447455
     
    480488 */
    481489function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = '') {
    482     return update_metadata('comment', $comment_id, $meta_key, $meta_value, $prev_value);
     490    $updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
     491    if ( $updated ) {
     492        wp_cache_set( 'last_changed', microtime(), 'comment' );
     493    }
     494    return $updated;
    483495}
    484496
Note: See TracChangeset for help on using the changeset viewer.