Cache recent sales eligibility to reduce excessive DB queries

This commit is contained in:
Eric Jinks 2022-05-09 13:08:36 +10:00
parent 48ead02176
commit 3d68850d78
No known key found for this signature in database
GPG Key ID: 22C09ACBC4DC9279
1 changed files with 14 additions and 1 deletions

View File

@ -120,6 +120,16 @@ class WcPaySubscriptionsPage {
* @return bool * @return bool
*/ */
private function get_store_recent_sales_eligibility() { private function get_store_recent_sales_eligibility() {
$transient_key = 'woocommerce-wcpay-subscriptions_recent_sales_eligibility';
// Load from cache.
$is_eligible = get_transient( $transient_key );
// Valid cache found.
if ( false !== $is_eligible ) {
return $is_eligible;
}
// Get a single order that was marked as completed within the last 30 days. // Get a single order that was marked as completed within the last 30 days.
$orders = wc_get_orders( $orders = wc_get_orders(
array( array(
@ -129,7 +139,10 @@ class WcPaySubscriptionsPage {
) )
); );
return count( $orders ) >= 1; $is_eligible = count( $orders ) >= 1;
set_transient( $transient_key, $is_eligible, DAY_IN_SECONDS );
return $is_eligible;
} }
/** /**