Automattic\WooCommerce\Admin\API\Reports\PerformanceIndicators

Controller::get_stats_data()privateWC 1.0

Get report stats data, avoiding duplicate requests for stats that use the same endpoint.

Method of the class: Controller{}

No Hooks.

Return

WP_REST_Response|WP_Error. Report stats data.

Usage

// private - for code of main (parent) class only
$result = $this->get_stats_data( $report, $query_args );
$report(string) (required)
Report slug to request data for.
$query_args(array) (required)
Report query args.

Controller::get_stats_data() code WC 7.3.0

private function get_stats_data( $report, $query_args ) {
	// Return from cache if we've already requested these report stats.
	if ( isset( $this->stats_data[ $report ] ) ) {
		return $this->stats_data[ $report ];
	}

	// Request the report stats.
	$request_url = $this->endpoints[ $report ];
	$request     = new \WP_REST_Request( 'GET', $request_url );
	$request->set_param( 'before', $query_args['before'] );
	$request->set_param( 'after', $query_args['after'] );

	$response = rest_do_request( $request );

	// Cache the response.
	$this->stats_data[ $report ] = $response;

	return $response;
}