-
Notifications
You must be signed in to change notification settings - Fork 10.7k
[COT] Effectively synchronize orders from the posts table to the custom orders table #32817
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
Conversation
This constant contains the name of the setting that is used to determine if the roles of the custom orders table and the posts table (authoritative and backup) are reversed once synchronization of orders between both tables finishes. The logic was mistakenly implemented backwards. Also, as part of the fix the constant is moved to the CustomOrdersTableController class.
It's now maybe_start_synchronizing_pending_orders. Also, the method now contains all the logic needed to decide if a synchronization needs to actually be started.
This commit connects the logic of the DataSyncrhonizer class with the actual posts to COT synchronization implemented in the WPPostToCOTMigrator class, so orders are actually syncrhonized using scheduled actions. Additionally, a synchronization process is triggered whenever an order is created or modified, using the woocommerce_after_order_object_save hook.
- Rename to PostsToOrdersMigrationController (same for tests class) - Rename process_next_migration_batch method to migrate_orders - Rename process_single to migrate_order - Remove batch and checkpoint related methods (batch management is performed by DataSynchronizer class) - Adjust unit tests
…Table - Add meaningful docblock comments for the classes - Add type ints for parameters and return values in all mehtods
vedanshujain
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.
Seems like there is some issue with order counting logic, it is always showing me 1815 orders even when everything is synced. Investigating a bit more
| public const PENDING_SYNCHRONIZATION_FINISHED_ACTION = 'woocommerce_orders_sync_finished'; | ||
| public const PLACEHOLDER_ORDER_POST_TYPE = 'shop_order_placehold'; | ||
|
|
||
| private const ORDERS_SYNC_BATCH_SIZE = 50; |
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 can be increased to 250 as a default
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 have added the woocommerce_orders_cot_and_posts_sync_step_size filter to customize this if needed.
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 still increase the step size to at least 250. 50 per batch is really low
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.
Ok, done.
|
Looks like the issue was that I had COT already enabled and then had 1815 orders out of sync. Given that backfill isn't implemented, the count of orders was not going down. Should we allow to switch data stores when COT is authoritative, even with pending orders, till the time backfill is merged? Also, we can actually increase the batch size to 500 or 1000, I want folks during the testing time to run into issues so that we can calibrate to a more optimum number as default. WDYT? |
- The woocommerce_custom_orders_table_enabled option can now be manually altered even if there are orders out of sync - Saving settings will always restart the sync process, even if one is already in progress - Add the woocommerce_orders_cot_and_posts_sync_step_size filter
vedanshujain
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.
Left a minor comment, looks good otherwise 👍
| public const PENDING_SYNCHRONIZATION_FINISHED_ACTION = 'woocommerce_orders_sync_finished'; | ||
| public const PLACEHOLDER_ORDER_POST_TYPE = 'shop_order_placehold'; | ||
|
|
||
| private const ORDERS_SYNC_BATCH_SIZE = 50; |
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 still increase the step size to at least 250. 50 per batch is really low
|
Hi @vedanshujain, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
All Submissions:
Changes proposed in this Pull Request:
TLDR:
This pull request combines the the settings UI/scheduled actions for orders sync work that was implemented in #32062 (and adjusted in #32706) with the posts/meta tables to custom tables migration classes that were implemented in #32034 and #32640. Additionally, creating and updating orders will now cause a synchronization process to be started, provided that synchronization is enabled. It also fixes a bug related to the automatic authoritative table switch and does some significant refactor on the migration classes.
More precisely:
DataSynchronizerclass will now effectively synchronize orders from the posts table to the custom orders table (but not the other way around! That part will be implemented separately).DataSynchronizerclass (viawoocommerce_after_order_object_savehook) and will start a data synchronization process (only if data synchronization is enabled in settings).Database\Migrations\CustomOrderTablenamespace have been refactored:wp option update woocommerce_custom_orders_table_enabled yes|no.woocommerce_orders_cot_and_posts_sync_step_size, to customize the count of orders that will be synchronized in each scheduled action run.NOTE: Given the scope of this pull request it's recommended to review the individual commits separately.
How to test the changes in this Pull Request:
Prerrequisite: having some orders in the posts table.
woocommerce.php:If you hadn't created the orders table previously, go to Status - Tools and run the "Create and fill custom orders table" tool. If you had, make sure that the table is empty (
truncate table wp_wc_ordersis fine).Go to WooCommerce - Settings - Advanced - Custom data stores, you should see a message saying that there are out of sync orders (all your orders, actually) but no mention to sync being in progress.
Make sure that the "Use the WordPress table" radio is selected and that "Keep the posts table and the orders table synchronized" is checked, and save (save even if you didn't need to change anything).
Once the page reloads, you'll see that the message has changed to indicate that the sync process is in progress. Reload again repeatedly, until the message disappears.
Verify that the
wp_wc_orderstable now contains proper entries for all the existing orders.Repeat the process (manually truncate the table, save settings with "Keep the posts table and the orders table synchronized" checked) but this time, once the first reload of the settings page check "Switch to using the orders table as the authoritative data store when sync finishes" and save. Now, after the sync finishes you should see that the "Use the WooCommerce orders table" is selected instead.
Make the posts table authoritative again.
Modify any of the existing orders, for example change its status.
Immediately after the previous step reload the settings page. You should see that the message appears again saying that there's one order pending sync, and that the sync is in progress.
Once the sync has happened verify that the corresponding order (same value for the
idfield) has been updated accordingly inwp_wc_orders.Other information:
pnpm nx affected --target=changelog?FOR PR REVIEWER ONLY: