-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add Auth token for search/featured extensions requests #28719
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
Add Auth token for search/featured extensions requests #28719
Conversation
WooCommerce.com will provide this list of products.
The featured extension list was static but now it's fetched from WooCommerce.com and may change more frequently. Reducing the cache duration to allow users to see changes much more quickly.
| $headers['Authorization'] = 'Bearer ' . $auth['access_token']; | ||
| } | ||
|
|
||
| $raw_extensions = wp_remote_get( |
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.
@raicem could we change this to wp_safe_remote_get?
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.
I agree that's a good idea.
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.
Ah, sorry. I have overlooked this. Fixed with this commit: eb3ba82
| $featured = json_decode( wp_remote_retrieve_body( $raw_featured ) ); | ||
| if ( $featured ) { | ||
| set_transient( 'wc_addons_featured', $featured, WEEK_IN_SECONDS ); | ||
| set_transient( 'wc_addons_featured', $featured, DAY_IN_SECONDS ); |
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.
@mattyza do you think that it’s ok to keep caching featured page content, or should we stop caching it?
Caching reduces the number of requests to WooCommerce.com, but it prevents us from making immediate changes.
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.
Perhaps a job for another day, but it seems to me like the optimal approach would be:
- Continue to cache for performance reasons, as well to increase the likelihood of seeing content if for some reason the site can't connect to WCCOM
- Clear this cache on installation/uninstallation/activation/deactivation of a plugin, resync of connection to WCCOM, etc.: this way, if a customer buys a new plugin they're likely to see the same recommendations... but then if they install it their recommendations will get updated!
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.
This makes sense @Dan-Q. Leaving the caching to last a day will keep the number of requests small but it will still allow us to change Algolia rules and to know that the changes will apply within 24 hours.
To keep cache clearing simple I suggest that we just add it to the subscriptions helper API call https://github.com/Automattic/woocommerce.com/blob/475ada19df47a07ac057a4fa1c207d129be1eb8a/plugins/woocommerce/includes/admin/helper/class-wc-helper.php#L1264
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.
If we decide to make any changes, can we do them in a separate PR? To avoid delaying this PR.
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.
Caching definitely makes sense, here. As Dan mentioned, having a way to invalidate this cache on demand is important. This can be done on disconnecting and reconnecting to WooCommerce.com, which would give Happiness Engineers a way to instruct customers to refresh their cache if needed.
There are, I'm sure, other options which we could explore in future PRs.
Caching for 1 day seems reasonable to me.
bgrgicak
left a comment
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.
Thanks @raicem! This looks great and works as expected 🎉
Dan-Q
left a comment
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.
Looks good!
It might have been nice to avoid repetition by refactoring-out the duplicated bits, but I suggest that waits until we inevitably end up adding authorization tokens to more requests. ;-)
(Also: I wonder if down the line we might want some hooks associated with the get_extension_data and get_featured requests to make adding tokens more-modular.)
Anyway, this looks good to me, for sure.
|
I have removed |
claudiosanches
left a comment
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.
@raicem great work!
Everything seems to be working as expected.
Could you please address this change: https://github.com/woocommerce/woocommerce/pull/28719/files#r552430798
Thanks!
| $headers['Authorization'] = 'Bearer ' . $auth['access_token']; | ||
| } | ||
|
|
||
| $raw_extensions = wp_remote_get( |
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.
I agree that's a good idea.
claudiosanches
left a comment
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.
Great work!
All Submissions:
Changes proposed in this Pull Request:
wp_safe_remote_getfor it instead ofwp_remote_get.How to test the changes in this Pull Request:
When not authenticated to the WooCommerce.com go to the
WooCommerce->Extensionspage. The featured tab should work as before. Making a search on the marketplace should also work as before.When authenticated to the WooCommerce.com, featured and search tabs should keep working the same. This time they should include the
Authorizationheader containing theaccess_token.Further testing for WooCommerce.com
If you have WooCommerce.com running locally and would like to test this feature you can use this repo to create a new store using this branch of WooCommerce plug-in.
woocommerce.comtowoocommerce.teston this fileAuthorizationheader info printed in thedebug.logOther information:
Changelog entry