Skip to content

Conversation

@coder-karen
Copy link
Contributor

@coder-karen coder-karen commented Nov 7, 2025

Closes SYNC-164

Proposed changes:

  • This PR prevents woocommerce_update_order_item and woocommerce_after_order_object_save action items being synced if there are no changes within a specific time window (due to a transient or persistent object cache if present), if the order is saved more than once in that time period.
  • This can happen if clicking the 'Recalculate' button in an order after making some changes such as a refund, then pressing 'Update' on the order as well.
  • The changes include adding a 5 minute window (currently) for a transient / cache. We also exclude changes to only the date modified or changed of the order if no other changes.
  • Even though the changes are applied to on_before_enqueue_order_save, which is hooked into the jetpack_sync_before_enqueue_woocommerce_after_{$type}_object_save filter, in this save flow both the per‑item updates and the order save occur in the same request. With our before‑enqueue guard, that request ends up with nothing meaningful to send, so those per‑item woocommerce_update_order_item events are not synced in this path.

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

SYNC-164

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

No.

Testing instructions:

To replicate the issue:

  • On a local development site or a JN test site with Jetpack and WooCommerce installed (and set to use HPOS ( /wp-admin/admin.php?page=wc-settings&tab=advanced):
  • Create a new order and add several order items.
  • Make sure you are watching logs for your site - visit 571a247b6623a0aa62165b5e4e2c7b10-logstash but replace the filter URL with your test site URL
  • Apply a refund to each of the order items and click 'save'.
  • View the actions via logstash
  • View the order ad order items on the cache site. Using wpsh when sandboxed: gpr select * from wp_YOURBLOGID_wc_orders and gpr select * from wp_YOURBLOGID_woocommerce_order_itemmeta
  • Then, click on 'Update' (or 'Recalculate').
  • You should see a woocommerce_after_order_object_save action synced, as well as one woocommerce_update_order_item for each order item.
  • Check the order via wpsh, nothing should have changed.

To test the changes:

  • Apply this PR using the Jetpack beta tester plugin.
  • Follow the same steps as above.
  • After clicking 'Update' or 'Recalculate' after a refund of order items, there should be no new actions synced if within 5 minutes of the refund.
  • Checking via the order via wpsh, nothing should have changed.
  • If you take another action in that same 5 minute window, eg updating an order item total, then clicking save or update should correctly sync the corresponding action.

@coder-karen coder-karen self-assigned this Nov 7, 2025
@coder-karen coder-karen added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress [Package] Sync labels Nov 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

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 WoA dev 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 (Jetpack or WordPress.com Site Helper), and enable the update/sync-hpos-orders-save-no-changes branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/sync-hpos-orders-save-no-changes
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/sync-hpos-orders-save-no-changes

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
Contributor

github-actions bot commented Nov 7, 2025

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 Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control
Copy link

jp-launch-control bot commented Nov 7, 2025

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/sync/src/modules/class-woocommerce-hpos-orders.php 0/209 (0.00%) 0.00% 15 💔

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

@coder-karen coder-karen force-pushed the update/sync-hpos-orders-save-no-changes branch from d82a818 to 4975a0e Compare November 7, 2025 17:08
@coder-karen coder-karen marked this pull request as ready for review November 10, 2025 12:40
@coder-karen coder-karen added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Nov 10, 2025
@coder-karen coder-karen requested review from a team and fgiannar November 10, 2025 13:04
@coder-karen coder-karen added [Status] In Progress and removed [Status] Needs Review This PR is ready for review. labels Nov 10, 2025
@coder-karen coder-karen added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Nov 10, 2025
/**
* Cache expiration for storing order content signatures.
*/
const CACHE_EXPIRATION = 5 * MINUTE_IN_SECONDS;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be longer?

@coder-karen
Copy link
Contributor Author

After speaking with @fgiannar who mentioned the impact on checksums - fix checksums will run every time the cache site does not match the remote site, and that includes as little as the modified date - I'll close this. In short the benefits may be negligible.

@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Sync [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants