Changeset 41848
- Timestamp:
- 10/12/2017 02:58:58 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment.php
r41704 r41848 424 424 */ 425 425 function 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; 427 431 } 428 432 … … 443 447 */ 444 448 function 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; 446 454 } 447 455 … … 480 488 */ 481 489 function 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; 483 495 } 484 496 -
trunk/tests/phpunit/tests/comment/query.php
r41287 r41848 3026 3026 $this->assertEquals( $number_of_queries, $wpdb->num_queries ); 3027 3027 } 3028 3029 /** 3030 * @ticket 40669 3031 */ 3032 public function test_add_comment_meta_should_invalidate_query_cache() { 3033 global $wpdb; 3034 3035 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 3036 $c1 = self::factory()->comment->create_post_comments( $p, 1 ); 3037 $c2 = self::factory()->comment->create_post_comments( $p, 1 ); 3038 3039 foreach ( $c1 as $cid ) { 3040 add_comment_meta( $cid, 'sauce', 'fire' ); 3041 } 3042 3043 $cached = get_comments( array( 3044 'post_id' => $p, 3045 'fields' => 'ids', 3046 'meta_query' => array( 3047 array( 3048 'key' => 'sauce', 3049 'value' => 'fire', 3050 ), 3051 ) 3052 ) ); 3053 3054 $this->assertEqualSets( $c1, $cached ); 3055 3056 foreach ( $c2 as $cid ) { 3057 add_comment_meta( $cid, 'sauce', 'fire' ); 3058 } 3059 3060 $found = get_comments( array( 3061 'post_id' => $p, 3062 'fields' => 'ids', 3063 'meta_query' => array( 3064 array( 3065 'key' => 'sauce', 3066 'value' => 'fire', 3067 ), 3068 ) 3069 ) ); 3070 3071 $this->assertEqualSets( array_merge( $c1, $c2 ), $found ); 3072 } 3073 3074 /** 3075 * @ticket 40669 3076 */ 3077 public function test_update_comment_meta_should_invalidate_query_cache() { 3078 global $wpdb; 3079 3080 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 3081 $c1 = self::factory()->comment->create_post_comments( $p, 1 ); 3082 $c2 = self::factory()->comment->create_post_comments( $p, 1 ); 3083 3084 foreach ( array_merge( $c1, $c2 ) as $cid ) { 3085 add_comment_meta( $cid, 'sauce', 'fire' ); 3086 } 3087 3088 $cached = get_comments( array( 3089 'post_id' => $p, 3090 'fields' => 'ids', 3091 'meta_query' => array( 3092 array( 3093 'key' => 'sauce', 3094 'value' => 'fire', 3095 ), 3096 ) 3097 ) ); 3098 3099 $this->assertEqualSets( array_merge( $c1, $c2 ), $cached ); 3100 3101 foreach ( $c2 as $cid ) { 3102 update_comment_meta( $cid, 'sauce', 'foo' ); 3103 } 3104 3105 $found = get_comments( array( 3106 'post_id' => $p, 3107 'fields' => 'ids', 3108 'meta_query' => array( 3109 array( 3110 'key' => 'sauce', 3111 'value' => 'fire', 3112 ), 3113 ) 3114 ) ); 3115 3116 $this->assertEqualSets( $c1, $found ); 3117 } 3118 3119 /** 3120 * @ticket 40669 3121 */ 3122 public function test_delete_comment_meta_should_invalidate_query_cache() { 3123 global $wpdb; 3124 3125 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 3126 $c1 = self::factory()->comment->create_post_comments( $p, 1 ); 3127 $c2 = self::factory()->comment->create_post_comments( $p, 1 ); 3128 3129 foreach ( array_merge( $c1, $c2 ) as $cid ) { 3130 add_comment_meta( $cid, 'sauce', 'fire' ); 3131 } 3132 3133 $cached = get_comments( array( 3134 'post_id' => $p, 3135 'fields' => 'ids', 3136 'meta_query' => array( 3137 array( 3138 'key' => 'sauce', 3139 'value' => 'fire', 3140 ), 3141 ) 3142 ) ); 3143 3144 $this->assertEqualSets( array_merge( $c1, $c2 ), $cached ); 3145 3146 foreach ( $c2 as $cid ) { 3147 delete_comment_meta( $cid, 'sauce' ); 3148 } 3149 3150 $found = get_comments( array( 3151 'post_id' => $p, 3152 'fields' => 'ids', 3153 'meta_query' => array( 3154 array( 3155 'key' => 'sauce', 3156 'value' => 'fire', 3157 ), 3158 ) 3159 ) ); 3160 3161 $this->assertEqualSets( $c1, $found ); 3162 } 3028 3163 }
Note: See TracChangeset
for help on using the changeset viewer.