Abstract_WC_Order_Data_Store_CPT::prime_needs_processing_transientsprotectedWC 10.7.0

Prime the needs_processing transient cache for a batch of orders.

WC_Order::needs_processing() calls get_transient() per order, which triggers an individual wp_options query each time. By priming the object cache for all transient option names in a single query, we eliminate the N+1.

Method of the class: Abstract_WC_Order_Data_Store_CPT{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->prime_needs_processing_transients( $order_ids, $query_vars );
$order_ids(array) (required)
Order IDs to prime cache for.
$query_vars(array) (required)
Query vars for the query.

Changelog

Since 10.7.0 Introduced.

Abstract_WC_Order_Data_Store_CPT::prime_needs_processing_transients() code WC 10.7.0

protected function prime_needs_processing_transients( $order_ids, $query_vars ) {
	$option_names = array();
	foreach ( $order_ids as $order_id ) {
		$option_names[] = '_transient_wc_order_' . $order_id . '_needs_processing';
		$option_names[] = '_transient_timeout_wc_order_' . $order_id . '_needs_processing';
	}

	wp_prime_option_caches( $option_names );
}