Skip to content
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

Prevent stores from calling helper API when local cache is not functioning #36846

Draft
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

thilinah
Copy link
Contributor

@thilinah thilinah commented Feb 15, 2023

All Submissions:

Changes proposed in this Pull Request:

Connected WooCommerce stores send requests to helper API for fetching details related to subscriptions and to get information about plugin updates. The responses from these API endpoints are cached to prevent stores from sending multiple requests frequently.

For example, the GET subscriptions request is cached for 1 hour and POST update-check request is cached for 12 hours.

But for some stores, the cache can be completely broken due to DB having a full disk. This is because when set_transient is called if the object cache is not configured for the site wp options table will be used to store the transient value. (further discussions in this P2 post and the issue)

Since the response from Helper API GET subscriptions and POST update-check is not the cached store will keep sending these requests. Basically this PR will block stores from calling above two endpoints if site local cache is not functioning.

Find more details on this P2 post.

Closes # .

  • This PR is a very minor change/addition and does not require testing instructions (if checked you can ignore/remove the next section).

How to test the changes in this Pull Request:

  1. Make sure the site is connected to WCCOM via wp-admin/admin.php?page=wc-addons&section=helper
  2. Add the following code into a mu-plugin to trick helper API client to think that the cache is broken.
add_filter( 'pre_transient__wc_helper_api_cache_test', function() {
	return 0;
} );
  1. Run wp cache flush to remove any previously stored subscription response.
  2. Visit My subscriptions page wp-admin/admin.php?page=wc-addons&section=helper
  3. There should be an error mentioning Could not find any subscriptions on your WooCommerce.com account
    Screenshot 2023-02-15 at 17 26 24
  4. Also there should be a log entry indicating the helper API request is skipped due to broken cache.
    Screenshot 2023-02-15 at 13 13 54
  5. Same should happen when pressing Update button under My Subscriptions.
  6. wp wc com extension list command should be blocked from making getting the subscription list.
  7. Now remove the hook added in step 2 and notice that the update check and subscription requests are working fine.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Feb 15, 2023
@thilinah thilinah self-assigned this Feb 15, 2023
@codecov
Copy link

codecov bot commented Feb 15, 2023

Codecov Report

Merging #36846 (4a624e2) into trunk (5b27b02) will increase coverage by 0.0%.
The diff coverage is 63.3%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             trunk   #36846   +/-   ##
========================================
  Coverage     46.7%    46.7%           
- Complexity   17164    17170    +6     
========================================
  Files          429      429           
  Lines        64734    64759   +25     
========================================
+ Hits         30203    30217   +14     
- Misses       34531    34542   +11     
Impacted Files Coverage Δ
...ugins/woocommerce/includes/class-wc-post-types.php 2.9% <0.0%> (ø)
...oocommerce/includes/class-wc-regenerate-images.php 18.9% <0.0%> (ø)
...commerce/includes/admin/helper/class-wc-helper.php 7.7% <33.3%> (+0.1%) ⬆️
.../includes/admin/helper/class-wc-helper-updater.php 27.8% <44.4%> (+0.1%) ⬆️
.../woocommerce/includes/wc-conditional-functions.php 28.2% <85.7%> (+3.7%) ⬆️
...udes/admin/settings/class-wc-settings-accounts.php 97.5% <100.0%> (ø)
...lugins/woocommerce/includes/class-wc-countries.php 86.7% <100.0%> (ø)
...includes/emails/class-wc-email-cancelled-order.php 88.9% <100.0%> (ø)
...s/emails/class-wc-email-customer-on-hold-order.php 81.2% <100.0%> (ø)
...lugins/woocommerce/includes/wc-order-functions.php 76.3% <100.0%> (ø)
... and 7 more

@github-actions
Copy link
Contributor

github-actions bot commented Feb 15, 2023

Test Results Summary

Commit SHA: 4a624e2

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202611m 11s
E2E Tests189006019518m 38s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@mattyza mattyza requested review from a team and psealock and removed request for a team February 16, 2023 12:49
@rcstr rcstr added this to the 7.6.0 milestone Feb 21, 2023
Copy link
Member

@rcstr rcstr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@psealock psealock requested review from a team and vedanshujain and removed request for a team March 15, 2023 01:27
@thilinah thilinah marked this pull request as draft March 21, 2023 16:19
@thilinah thilinah removed this from the 7.6.0 milestone Mar 30, 2023
@barryhughes barryhughes removed the request for review from vedanshujain September 26, 2023 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants