Skip to content

My Jetpack: Improve product cache handling on Jetpack AI#34428

Merged
lhkowalski merged 7 commits intotrunkfrom
update/my-jetpack-handle-product-cache-on-jetpack-ai
Dec 4, 2023
Merged

My Jetpack: Improve product cache handling on Jetpack AI#34428
lhkowalski merged 7 commits intotrunkfrom
update/my-jetpack-handle-product-cache-on-jetpack-ai

Conversation

@lhkowalski
Copy link
Copy Markdown
Contributor

@lhkowalski lhkowalski commented Dec 1, 2023

Fixes #34347.

Proposed changes:

  • Busts the product cache data when the tiers are enabled but the price_tier_list is empty (meaning that the site does not have tier prices yet, meaning it needs a fresh product information)
  • If the new data does not contain tiers too (unexpected), just fails gracefully without returning any price, showing the interstitial without the price
  • To allow it, include support for cache busting on the Wpcom_Products::get_product() function

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

Fill the cache with production product data (no tiers)

  • Launch a new JN site running this branch and connect it (or remove any Jetpack AI subscription from you local testing site)
  • Go to Jetpack > My Jetpack, scroll to the Jetpack AI card and click the purchase button
  • You should see the Jetpack AI product interstitial with the price for the current unlimited plan
  • Now your cache is filled with production values (no tiers)

Testing with the tiers

  • Now go to your sandbox, apply D126642-code and rebase it with trunk
  • Point the site to your sandbox (remember to enable HTTP access to it if it's a JN site)
  • Leave the tiers disabled for now and confirm the Jetpack AI interstitial is still showing the price for the legacy plan
  • Enable the tiers using the filter:
add_filter( 'jetpack_ai_tier_plans_enabled', '__return_true' );
  • Reload the Jetpack AI interstitial and confirm that you see the price for the 100 requests tier (the interstitial will state "100 requests" on the feature list)
    • If you have QueryMonitor installed on the test site, you can inspect the HTTP API Calls section and confirm a request was made to https://public-api.wordpress.com/rest/v1.1/sites/BLOG_ID/products/, to refresh the cache:
Screenshot 2023-12-01 at 17 04 08
  • Buy the 100 requests tier (make sure you are sandboxing the store) and then go back to the product interstitial (Jetpack > My Jetpack, scroll the page to the Jetpack AI card, click Purchase)
  • Confirm that now you see the price for the 200 requests tier (before this change, you would see the price for the legacy unlimited plan, a wrong behavior)
  • Buy the 200 requests tier and proceed with the test again, to see if the 500 requests tier price is showed correctly too
  • No need to test on all the tiers, but you can if you would like to

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 1, 2023

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the update/my-jetpack-handle-product-cache-on-jetpack-ai branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack update/my-jetpack-handle-product-cache-on-jetpack-ai
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 1, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.

@lhkowalski lhkowalski marked this pull request as ready for review December 1, 2023 19:18
@lhkowalski lhkowalski added [Status] Needs Team Review Obsolete. Use Needs Review instead. and removed [Status] In Progress labels Dec 1, 2023
@lhkowalski lhkowalski changed the title My Jetpack: improve product cache handling on Jetpack AI My Jetpack: Improve product cache handling on Jetpack AI Dec 1, 2023
* if the list is still empty after the fresh data, we will
* default to empty pricing (by returning an empty array).
*/
if ( empty( $product->price_tier_list ) && isset( $info['tier-plans-enabled'] ) && $info['tier-plans-enabled'] === true ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When disconnected, $product returns an error and this causes a fatal on My Jetpack. We'll need a check there for an error response.

dhasilva
dhasilva previously approved these changes Dec 1, 2023
Copy link
Copy Markdown
Contributor

@dhasilva dhasilva left a comment

Choose a reason for hiding this comment

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

LGTM. Looking smooth now! 🚀

@lhkowalski lhkowalski enabled auto-merge (squash) December 4, 2023 17:19
@lhkowalski lhkowalski merged commit ce7b3c7 into trunk Dec 4, 2023
@lhkowalski lhkowalski deleted the update/my-jetpack-handle-product-cache-on-jetpack-ai branch December 4, 2023 17:55
@github-actions github-actions bot removed the [Status] Needs Team Review Obsolete. Use Needs Review instead. label Dec 4, 2023
sdixon194 pushed a commit that referenced this pull request Dec 5, 2023
* Only shows the price when the price information is available

* Support cache busting from the get_product method

* Renew product cache if tiers are enabled but there is no tier info on the cache

* Add changelog file

* Check for wp_error on feature data to handle Jetpack not being connected
@sdixon194
Copy link
Copy Markdown
Contributor

Cherry picked to release branch in 1980da3

zinigor added a commit that referenced this pull request Dec 25, 2023
* Add changelogs

* Changelog edits.

* Amend readme.txt

* Updated package versions for automattic/jetpack

* Updated package versions for automattic/jetpack-mu-wpcom-plugin

* My Jetpack: Improve product cache handling on Jetpack AI (#34428)

* Only shows the price when the price information is available

* Support cache busting from the get_product method

* Renew product cache if tiers are enabled but there is no tier info on the cache

* Add changelog file

* Check for wp_error on feature data to handle Jetpack not being connected

* Release my-jetpack

* Update my-jetpack dependency

* Update changelog and readme.txt for Jetpack 12.9

* Carousel: fix unresponsive navigation (#34678)

* Changelog adn readme for 12.9.1

* Bump version numbers to 12.9.1

* Fix token subscription service name (#34723)

* Rename Token_Subscript_Service to Abstract_Token_Subscription_Service

* changelog

* Allow old class just in case

* `use` classes at the top to shorten up the class check.

* Release Videopress 0.21.3.1

---------

Co-authored-by: Kuba Birecki <kuba.birecki@crystalplanet.io>
Co-authored-by: Luiz Kowalski <lhkowalski@gmail.com>
Co-authored-by: sdixon194 <steve.dixon@automattic.com>
Co-authored-by: Kev <kevin.zoschke@automattic.com>
Co-authored-by: Christopher Smith <8002138+chrisfromthelc@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI Tiered Plans: bust product data cache on My Jetpack to fetch the updated version

4 participants