Don't query products all products for empty categories (https://github.com/woocommerce/woocommerce-admin/pull/1911)

This commit is contained in:
Joshua T Flowers 2019-03-26 13:21:46 +08:00 committed by GitHub
parent ce6fcdabbe
commit ebac101b51
1 changed files with 6 additions and 1 deletions

View File

@ -730,6 +730,11 @@ class WC_Admin_Reports_Data_Store {
$cat_slugs[] = $product_cat->slug; $cat_slugs[] = $product_cat->slug;
} }
} }
if ( empty( $cat_slugs ) ) {
return array();
}
$args = array( $args = array(
'category' => $cat_slugs, 'category' => $cat_slugs,
'limit' => -1, 'limit' => -1,
@ -749,7 +754,7 @@ class WC_Admin_Reports_Data_Store {
if ( isset( $query_args['categories'] ) && is_array( $query_args['categories'] ) && count( $query_args['categories'] ) > 0 ) { if ( isset( $query_args['categories'] ) && is_array( $query_args['categories'] ) && count( $query_args['categories'] ) > 0 ) {
$included_products = $this->get_products_by_cat_ids( $query_args['categories'] ); $included_products = $this->get_products_by_cat_ids( $query_args['categories'] );
$included_products = wc_list_pluck( $included_products, 'get_id' ); $included_products = empty( $included_products ) ? array( '-1' ) : wc_list_pluck( $included_products, 'get_id' );
} }
if ( isset( $query_args['product_includes'] ) && is_array( $query_args['product_includes'] ) && count( $query_args['product_includes'] ) > 0 ) { if ( isset( $query_args['product_includes'] ) && is_array( $query_args['product_includes'] ) && count( $query_args['product_includes'] ) > 0 ) {