Make WordPress Core


Ignore:
Timestamp:
04/13/2022 02:55:34 AM (3 years ago)
Author:
peterwilsoncc
Message:

Cache API: Improve cache key generation in WP_Comment_Query.

Discard the parameters update_comment_meta_cache and update_comment_post_cache when generating the cache key as neither have an effect on the database query generated.

Props uday17035, spacedmonkey.
Fixes #55460.

File:
1 edited

Legend:

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

    r52010 r53169  
    49424942        return array( get_comment( $c ) );
    49434943    }
     4944
     4945    /**
     4946     * @ticket 55460
     4947     */
     4948    public function test_comment_cache_key_should_ignore_unset_params() {
     4949        $p = self::factory()->post->create();
     4950        $c = self::factory()->comment->create( array( 'comment_post_ID' => $p ) );
     4951
     4952        $_args = array(
     4953            'post_id'                   => $p,
     4954            'fields'                    => 'ids',
     4955            'update_comment_meta_cache' => true,
     4956            'update_comment_post_cache' => false,
     4957        );
     4958
     4959        $q1 = new WP_Comment_Query();
     4960        $q1->query( $_args );
     4961
     4962        $num_queries_all_args = get_num_queries();
     4963
     4964        // Ignore 'fields', 'update_comment_meta_cache', 'update_comment_post_cache'.
     4965        unset( $_args['fields'], $_args['update_comment_meta_cache'], $_args['update_comment_post_cache'] );
     4966        $q2 = new WP_Comment_Query();
     4967        $q2->query( $_args );
     4968
     4969        $this->assertSame( $num_queries_all_args, get_num_queries() );
     4970    }
    49444971}
Note: See TracChangeset for help on using the changeset viewer.