Make WordPress Core


Ignore:
Timestamp:
09/25/2015 02:34:20 PM (11 years ago)
Author:
boonebgorges
Message:

Improve pagination internals in WP_Comment_Query.

WP_Comment_Query will now report the total number of comments matching the
query params (comments_found), as well as the total number of pages required
to display these comments (max_num_pages). Because SQL_CALC_FOUND_ROWS
queries can introduce a lot of overhead in some cases, we disable the feature
by default. Pass no_found_rows=false to WP_Comment_Query to enable the
count. (We use the negative parameter name 'no_found_rows' for parity with
WP_Query.)

Props wonderboymusic, boonebgorges.
See #8071.

File:
1 edited

Legend:

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

    r34310 r34544  
    18741874
    18751875        }
     1876
     1877        /**
     1878         * @ticket 8071
     1879         */
     1880        public function test_no_found_rows_should_default_to_true() {
     1881                $comments = $this->factory->comment->create_many( 3, array( 'comment_post_ID' => $this->post_id ) );
     1882
     1883                $q = new WP_Comment_Query( array(
     1884                        'post_id' => $this->post_id,
     1885                        'number' => 2,
     1886                ) );
     1887
     1888                $this->assertEquals( 0, $q->found_comments );
     1889                $this->assertEquals( 0, $q->max_num_pages );
     1890        }
     1891
     1892        /**
     1893         * @ticket 8071
     1894         */
     1895        public function test_should_respect_no_found_rows_true() {
     1896                $comments = $this->factory->comment->create_many( 3, array( 'comment_post_ID' => $this->post_id ) );
     1897
     1898                $q = new WP_Comment_Query( array(
     1899                        'post_id' => $this->post_id,
     1900                        'number' => 2,
     1901                        'no_found_rows' => true,
     1902                ) );
     1903
     1904                $this->assertEquals( 0, $q->found_comments );
     1905                $this->assertEquals( 0, $q->max_num_pages );
     1906        }
     1907
     1908        /**
     1909         * @ticket 8071
     1910         */
     1911        public function test_should_respect_no_found_rows_false() {
     1912                $comments = $this->factory->comment->create_many( 3, array( 'comment_post_ID' => $this->post_id ) );
     1913
     1914                $q = new WP_Comment_Query( array(
     1915                        'post_id' => $this->post_id,
     1916                        'number' => 2,
     1917                        'no_found_rows' => false,
     1918                ) );
     1919
     1920                $this->assertEquals( 3, $q->found_comments );
     1921                $this->assertEquals( 2, $q->max_num_pages );
     1922        }
    18761923}
Note: See TracChangeset for help on using the changeset viewer.