Make WordPress Core


Ignore:
Timestamp:
11/20/2014 01:51:38 AM (10 years ago)
Author:
boonebgorges
Message:

Return an empty array from get_approved_comments() when $post_id is empty.

This behavior was broken when moving the internals to WP_Comment_Query in
[30098]. As a result, get_approved_comments( 0 ) was fetching *all* approved
comments, causing performance issues.

Props dd32.
Fixes #30412.

File:
1 edited

Legend:

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

    r30266 r30402  
    2929
    3030        $this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
     31    }
     32
     33    public function test_query_post_id_0() {
     34        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     35
     36        $q = new WP_Comment_Query();
     37        $found = $q->query( array(
     38            'post_id' => 0,
     39            'fields' => 'ids',
     40        ) );
     41
     42        $this->assertEqualSets( array( $c1 ), $found );
    3143    }
    3244
Note: See TracChangeset for help on using the changeset viewer.