Skip to content

Commit 53e7591

Browse files
authored
Improve slow query for legacy subscriptions on WC status tools page by caching the data (#3848)
* cache the legacy sepa subscriptions order count to avoid frequent db calls
1 parent d02e3ee commit 53e7591

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* Fix - Improve the appearance of Stripe elements in checkout pages to match the store theme.
4242
* Fix - Hide ECE button for synced subscription variations.
4343
* Fix - Use the original shipping address for Amazon Pay pay for orders.
44+
* Tweak - Improve slow query for legacy SEPA subscriptions on WC status tools page by caching the data.
4445
* Tweak - Improve settings page load by delaying oauth URL generation.
4546
* Tweak - Update the Woo logo in the Configure connection modal
4647

includes/migrations/class-wc-stripe-subscriptions-repairer-legacy-sepa-tokens.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
class WC_Stripe_Subscriptions_Repairer_Legacy_SEPA_Tokens extends WCS_Background_Repairer {
1414

15+
const LEGACY_SEPA_SUBSCRIPTIONS_COUNT = 'woocommerce_stripe_subscriptions_with_legacy_sepa';
16+
1517
/**
1618
* The transient key used to store the progress of the repair.
1719
*
@@ -341,6 +343,12 @@ public function add_debug_tool( $tools ) {
341343
* @return bool True if there are subscriptions using the Legacy SEPA payment method, false otherwise.
342344
*/
343345
private function has_legacy_sepa_subscriptions() {
346+
$cached_legacy_sepa_subscriptions_count = get_transient( self::LEGACY_SEPA_SUBSCRIPTIONS_COUNT );
347+
348+
if ( false !== $cached_legacy_sepa_subscriptions_count ) {
349+
return $cached_legacy_sepa_subscriptions_count > 0;
350+
}
351+
344352
$subscriptions = wc_get_orders(
345353
[
346354
'return' => 'ids',
@@ -350,8 +358,11 @@ private function has_legacy_sepa_subscriptions() {
350358
'payment_method' => WC_Gateway_Stripe_Sepa::ID,
351359
]
352360
);
361+
$subscriptions_count = count( $subscriptions );
362+
363+
set_transient( self::LEGACY_SEPA_SUBSCRIPTIONS_COUNT, $subscriptions_count, 12 * HOUR_IN_SECONDS );
353364

354-
return ! empty( $subscriptions );
365+
return $subscriptions_count > 0;
355366
}
356367

357368
/**

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
151151
* Fix - Improve the appearance of Stripe elements in checkout pages to match the store theme.
152152
* Fix - Hide ECE button for synced subscription variations.
153153
* Fix - Use the original shipping address for Amazon Pay pay for orders.
154+
* Tweak - Improve slow query for legacy SEPA subscriptions on WC status tools page by caching the data.
154155
* Tweak - Improve settings page load by delaying oauth URL generation.
155156
* Tweak - Update the Woo logo in the Configure connection modal
156157

0 commit comments

Comments
 (0)