Make WordPress Core


Ignore:
Timestamp:
09/17/2015 07:29:46 PM (9 years ago)
Author:
boonebgorges
Message:

Prime comment meta caches in WP_Comment_Query.

The new 'update_comment_meta_cache' parameter, which defaults to true, can
be used to disable this behavior.

update_comment_cache() has been updated to support an $update_meta_cache
parameter, which also updates to true; this matches the pattern we use for
priming post caches.

See #16894.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/metaCache.php

    r33926 r34268  
    44    protected $i = 0;
    55    protected $queries = 0;
     6
     7    /**
     8     * @ticket 16894
     9     */
     10    public function test_update_comment_meta_cache_should_default_to_true() {
     11        global $wpdb;
     12
     13        $p = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     14        $comment_ids = $this->factory->comment->create_post_comments( $p, 3 );
     15
     16        foreach ( $comment_ids as $cid ) {
     17            update_comment_meta( $cid, 'foo', 'bar' );
     18        }
     19
     20        $q = new WP_Comment_Query( array(
     21            'post_ID' => $p,
     22        ) );
     23
     24        $num_queries = $wpdb->num_queries;
     25        foreach ( $comment_ids as $cid ) {
     26            get_comment_meta( $cid, 'foo', 'bar' );
     27        }
     28
     29        $this->assertSame( $num_queries, $wpdb->num_queries );
     30    }
     31
     32    /**
     33     * @ticket 16894
     34     */
     35    public function test_update_comment_meta_cache_true() {
     36        global $wpdb;
     37
     38        $p = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     39        $comment_ids = $this->factory->comment->create_post_comments( $p, 3 );
     40
     41        foreach ( $comment_ids as $cid ) {
     42            update_comment_meta( $cid, 'foo', 'bar' );
     43        }
     44
     45        $q = new WP_Comment_Query( array(
     46            'post_ID' => $p,
     47            'update_comment_meta_cache' => true,
     48        ) );
     49
     50        $num_queries = $wpdb->num_queries;
     51        foreach ( $comment_ids as $cid ) {
     52            get_comment_meta( $cid, 'foo', 'bar' );
     53        }
     54
     55        $this->assertSame( $num_queries, $wpdb->num_queries );
     56    }
     57
     58    /**
     59     * @ticket 16894
     60     */
     61    public function test_update_comment_meta_cache_false() {
     62        global $wpdb;
     63
     64        $p = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     65        $comment_ids = $this->factory->comment->create_post_comments( $p, 3 );
     66
     67        foreach ( $comment_ids as $cid ) {
     68            update_comment_meta( $cid, 'foo', 'bar' );
     69        }
     70
     71        $q = new WP_Comment_Query( array(
     72            'post_ID' => $p,
     73            'update_comment_meta_cache' => false,
     74        ) );
     75
     76        $num_queries = $wpdb->num_queries;
     77        foreach ( $comment_ids as $cid ) {
     78            get_comment_meta( $cid, 'foo', 'bar' );
     79        }
     80
     81        $this->assertSame( $num_queries + 3, $wpdb->num_queries );
     82    }
    683
    784    public function test_comment_meta_cache() {
Note: See TracChangeset for help on using the changeset viewer.