-
Notifications
You must be signed in to change notification settings - Fork 72
Improve MultiCurrency cache strategy and switch to using API v2 for currency rates #10800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Test the buildOption 1. Jetpack Beta
Option 2. Jurassic Ninja - available for logged-in A12s🚀 Launch a JN site with this branch 🚀 ℹ️ Install this Tampermonkey script to get more options. Build info:
Note: the build is updated when a new commit is pushed to this PR. |
Size Change: 0 B Total Size: 1.26 MB ℹ️ View Unchanged
|
/** | ||
* Communicates with the WooPayments v2 API. | ||
*/ | ||
class WC_Payments_API_V2_Client extends WC_Payments_API_Client { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid inheritance. I think adding something like V2_ENDPOINT_REST_BASE
to the base class and using that in the method will be sufficient. It also allows the classes that call the API client not to be concerned of versions.
And we will be able to get rid of all the static/self changes, reducing the diff size.
And it will address the concern from the comment of 1:1 route match, which we will never have :)
$ttl = DAY_IN_SECONDS; | ||
} | ||
break; | ||
case self::CURRENCIES_KEY: | ||
// Refresh the errored currencies quickly, otherwise cache for 6h. | ||
$ttl = $cache_contents['errored'] ? 2 * MINUTE_IN_SECONDS : 6 * HOUR_IN_SECONDS; | ||
if ( defined( 'DOING_CRON' ) || is_admin() || Utils::is_admin_api_request() ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we need the DOING_CRON
check there TBH.
We should also check for is_cart
and is_checkout
in addition to or instead of the admin checks. We'd want to show updated prices on those pages I imagine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or feel free to ignore, perhaps this is good enough 🤔
Contributes to TRAPLAT-3377
Changes proposed in this Pull Request
We change the caching strategy for MultiCurrency (MCCY) rates by:
This way, we avoid excessive API spamming from busy stores while triggering cache refreshes by less demanding contexts (WP admin).
At the same time, we switch to using the API v2 endpoint which will has a better response time due to its internal caching of currency rates.
Context: p1748001425970059-slack-C01BPL3ALGP
Testing instructions
wp-content/uploads/wc-logs/woopayments-<date>...log
in your local client WordPress install.DELETE FROM wp_options WHERE option_name='wcpay_multi_currency_cached_currencies'
to delete thewcpay_multi_currency_cached_currencies
DB cache entry.WooCommerce > Settings > Multi-Currency
SELECT * FROM wp_options WHERE option_name='wcpay_multi_currency_cached_currencies'
npm run changelog
to add a changelog file, choosepatch
to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.Post merge