-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Implement queries for non-synchronized orders, and revamp COT related settings #32062
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
- Update settings UI - Start sync via scheduled actions when sync is enabled - Auto-switch authoritative table on sync finished if so configured - Disable auto-switch if sync is disabled - Show initial and current count of orders pending sync in settings UI
Use real SQL to get the count of unsynced orders.
|
While this works I have noticed that if the data synchronization process is in progress any page in the site takes ages to load, an meanwhile a bunch of synchronization steps happen. Perhaps I'm misusing Action Scheduler somehow? |
barryhughes
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.
Nice—left some notes (all minor items) but this is working well per testing instructions.
plugins/woocommerce/src/Internal/DataStores/Orders/CustomOrdersTableController.php
Outdated
Show resolved
Hide resolved
plugins/woocommerce/src/Internal/DataStores/Orders/CustomOrdersTableController.php
Outdated
Show resolved
Hide resolved
plugins/woocommerce/src/Internal/DataStores/Orders/DataSynchronizer.php
Outdated
Show resolved
Hide resolved
|
Hi @barryhughes, I have implemented your suggestions, thanks. However I've marked the pr as blocked until we decide what to do with the possible duplicated order ids issue. |
|
Hi @Konamiman, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
|
Merged after having agreed on the approach to avoid conflicting order ids (see p7bje6-3WQ-p2#comment-7101). A relevant point is that the |
All Submissions:
Changes proposed in this Pull Request:
The settings page (WooCommerce > Settings > Advanced > Custom data stores) now looks like this when there aren't any orders out of sync:
These settings can be freely modified.
Now, let's assume that sync is disabled and there are some orders of out of sync. The settings page will now look like this:
Note how the authoritative table can't be changed. There's also a check in the backend to prevent that setting from being changed if there are out of sync orders (an exception will be thrown).
Setting Keep the posts table and the orders tables synchronized and saving will start a synchronization process (not implemented yet), this will be done using Action Scheduler and each run will syncrhonize a batch of orders. The settings will change as follows once that happens:
Note how the warning message now says that sync is in progress, and includes the count of orders that were out of sync when the process started (this UI can be refined later by adding an actual progress bar or similar). Notice also the new Switch to using the orders/posts table as the authoritative data store for orders when sync finishes option: if set, the authoritative table for storing orders will be switched (from posts to orders or viceversa) once no more out of sync orders remain.
Worth noting that the Switch to using the orders/posts table as the authoritative data store for orders when sync finishes option will be automatically turned off once the table switch has happened. It will also be turned off if Keep the posts table and the orders tables synchronized itself is turned off. This is to prevent accidental/unexpected table switches.
There's one case in which orders can get out of sync even when we have automatic sync turned on: when some 3rd party code does direct modifications in the posts table. Automatic sync ensures that changes in an order propagate to the backup table only when the changes is made by WooCommerce itself.
When that happens, a synchronization process can be triggered by just saving the settings with the Keep the posts table and the orders tables synchronized setting on, even if it was already on (no need to turn it off, save, and turn it on again).
Closes #31769.
Closes #31770.
Closes #31771.
How to test the changes in this Pull Request:
Initial setup
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.
You can use the following SQL commands to populate the orders table with data from the posts table and force some of them to be out of sync (adjust the
LIMITclauses and the number of(null)entries as desired):Testing settings and scheduled actions with the fake out of sync orders count
This pull request introduces a mechanism to declare a fake count of orders out of sync, intended to ease the testing of the feature while it's in development. This mechanism is an option named
woocommerce_fake_orders_pending_sync_count. If it exists (it must be a number >= 0) the following will happen:DataSynchronizer::get_current_orders_pending_sync_countwill be the value of this option, no actual database access will be performed.DataSynchronizer::do_pending_orders_synchronizationmethod, which will be run by Action Scheduler, will simply update the value of this option with its current value minus one, until it reaches zero; no actual database access will be performed (note however that at the time of submitting this pull request the actual synchronization isn't implemented yet, so no database access would have been performed anyway).So with this, here's how to test:
wp option set woocommerce_fake_orders_pending_sync_count 0).Testing the query for out of sync order ids
Temporarily modify
DataSynchronizer::get_ids_of_orders_pending_syncso that it'spublicand run it from CLI as follows:where
typeis the value of one of theID_TYPE_...constants (see the header ofget_ids_of_orders_pending_syncfor details) andlimitis the maximum number of ids to return.Other information:
Changelog entry
FOR PR REVIEWER ONLY: