Fix 40075/avoid count query unless after first page (#40092)
* Avoid running a second query to account for incorrect totals if pagination is set too high if pagination isn't used. Fixes #40075 * Adding changelog entry
This commit is contained in:
parent
34cfbd94b4
commit
874bffc0db
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: performance
|
||||||
|
|
||||||
|
Prevent second query used to determine real post count from running if paging isn't being used.
|
|
@ -354,7 +354,7 @@ abstract class WC_REST_CRUD_Controller extends WC_REST_Posts_Controller {
|
||||||
$result = $query->query( $query_args );
|
$result = $query->query( $query_args );
|
||||||
|
|
||||||
$total_posts = $query->found_posts;
|
$total_posts = $query->found_posts;
|
||||||
if ( $total_posts < 1 ) {
|
if ( $total_posts < 1 && isset( $query_args['paged'] ) && absint( $query_args['paged'] ) > 1 ) {
|
||||||
// Out-of-bounds, run the query again without LIMIT for total count.
|
// Out-of-bounds, run the query again without LIMIT for total count.
|
||||||
unset( $query_args['paged'] );
|
unset( $query_args['paged'] );
|
||||||
$count_query = new WP_Query();
|
$count_query = new WP_Query();
|
||||||
|
|
|
@ -367,7 +367,7 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
|
||||||
$page = (int) $query_args['paged'];
|
$page = (int) $query_args['paged'];
|
||||||
$total_posts = $posts_query->found_posts;
|
$total_posts = $posts_query->found_posts;
|
||||||
|
|
||||||
if ( $total_posts < 1 ) {
|
if ( $total_posts < 1 && $page > 1 ) {
|
||||||
// Out-of-bounds, run the query again without LIMIT for total count.
|
// Out-of-bounds, run the query again without LIMIT for total count.
|
||||||
unset( $query_args['paged'] );
|
unset( $query_args['paged'] );
|
||||||
$count_query = new WP_Query();
|
$count_query = new WP_Query();
|
||||||
|
|
|
@ -93,7 +93,7 @@ class Controller extends GenericController implements ExportableInterface {
|
||||||
$result = $query->query( $query_args );
|
$result = $query->query( $query_args );
|
||||||
|
|
||||||
$total_posts = $query->found_posts;
|
$total_posts = $query->found_posts;
|
||||||
if ( $total_posts < 1 ) {
|
if ( $total_posts < 1 && isset( $query_args['paged'] ) && absint( $query_args['paged'] ) > 1 ) {
|
||||||
// Out-of-bounds, run the query again without LIMIT for total count.
|
// Out-of-bounds, run the query again without LIMIT for total count.
|
||||||
unset( $query_args['paged'] );
|
unset( $query_args['paged'] );
|
||||||
$count_query = new \WP_Query();
|
$count_query = new \WP_Query();
|
||||||
|
|
Loading…
Reference in New Issue