From 213397ffefdce50f97f6bda1fb3430ea67cdc23c Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Wed, 24 Jun 2020 18:58:16 +0530 Subject: [PATCH] Add support to prime refund cache in wc_order class. Fetching refunds call is an expensive query, so priming the cache where possible could be beneficial for better performance. --- includes/class-wc-order.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/includes/class-wc-order.php b/includes/class-wc-order.php index e364c84144c..5365224dda0 100644 --- a/includes/class-wc-order.php +++ b/includes/class-wc-order.php @@ -1792,6 +1792,16 @@ class WC_Order extends WC_Abstract_Order { |-------------------------------------------------------------------------- */ + /** + * Prime refunds cache, can be used before get_refunds to skip DB query. + * + * @param array $refunds array of WC_Order_Refund objects. + */ + public function prime_refunds_cache( $refunds ) { + $cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'refunds' . $this->get_id(); + wp_cache_set( $cache_key, $refunds, $this->cache_group ); + } + /** * Get order refunds. *