From 4c8a95cb899372f56e695f0a33effc8866d3861b Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Fri, 25 Jan 2019 13:29:59 +0100 Subject: [PATCH] Added fetching of db intervals for later use in zero-filling. --- ...c-admin-reports-taxes-stats-data-store.php | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-stats-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-stats-data-store.php index 8231bee89e3..c09f65a3351 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-stats-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-stats-data-store.php @@ -145,23 +145,24 @@ class WC_Admin_Reports_Taxes_Stats_Data_Store extends WC_Admin_Reports_Data_Stor $intervals_query = array(); $this->update_sql_query_params( $query_args, $totals_query, $intervals_query ); - $db_records_count = (int) $wpdb->get_var( - "SELECT COUNT(*) FROM ( - SELECT - {$intervals_query['select_clause']} AS time_interval - FROM - {$table_name} - {$intervals_query['from_clause']} - WHERE - 1=1 - {$intervals_query['where_time_clause']} - {$intervals_query['where_clause']} - GROUP BY - time_interval - ) AS t" + $db_intervals = $wpdb->get_col( + "SELECT + {$intervals_query['select_clause']} AS time_interval + FROM + {$table_name} + {$intervals_query['from_clause']} + WHERE + 1=1 + {$intervals_query['where_time_clause']} + {$intervals_query['where_clause']} + GROUP BY + time_interval" ); // WPCS: cache ok, DB call ok, unprepared SQL ok. - $total_pages = (int) ceil( $db_records_count / $intervals_query['per_page'] ); + $db_interval_count = count( $db_intervals ); + $expected_interval_count = WC_Admin_Reports_Interval::intervals_between( $query_args['after'], $query_args['before'], $query_args['interval'] ); + $total_pages = (int) ceil( $expected_interval_count / $intervals_query['per_page'] ); + if ( $query_args['page'] < 1 || $query_args['page'] > $total_pages ) { return $data; } @@ -219,7 +220,7 @@ class WC_Admin_Reports_Taxes_Stats_Data_Store extends WC_Admin_Reports_Data_Stor $data = (object) array( 'totals' => $totals, 'intervals' => $intervals, - 'total' => $db_records_count, + 'total' => $expected_interval_count, 'pages' => $total_pages, 'page_no' => (int) $query_args['page'], );