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
Add hook to allow disable of full batch api sync (e.g. for large stores) to avoid potential performance issues #2033
Add hook to allow disable of full batch api sync (e.g. for large stores) to avoid potential performance issues #2033
Conversation
- query loads all product IDs - which could be a lot - wp_count_posts uses a `COUNT()` sql statement which doesn't load anything - in my testing, WP_Query approach uses 40x more memory
…min tab" This reverts commit 3896e99. Reverting - will hide/adjust button server side
facebook-commerce.php
Outdated
* @var int Maximum number of products for full sync. | ||
* Used to disable full batch-API sync flows which may cause performance issues. | ||
**/ | ||
const MAX_PRODUCTS_FOR_FULL_SYNC = 500; |
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.
TBC - we need to determine what the appropriate threshold is. It may need to be smaller, but ideally we want this as large as we can safely get away with, to reduce the number of impacted stores.
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'm leaning towards 5000 or maybe 2500 here - the site that triggered the issue had 19k products.
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 2.6.0 running with 2k-5k products and products have been synced, these sites are running on a shared account on Siteground.
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.
That's useful info, thanks for setting these up @rcstr !
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'm thinking we expose a filter for max products for full sync, then hosts or sites can tweak this threshold to suit.
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 bump this up to 5k - that's approx a quarter of the 19k from the problematic site, and host/site can use the filter if they need a smaller threshold.
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.
(And let's test it - how big is the option with 5000 products?)
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.
Changes look good, haven't fully tested yet. I think this will be a good place to define wc_facebook_enable_product_sync
to be sure sync doesn't run
?> | ||
|
||
<h2> | ||
|
||
<?php esc_html_e( 'Product sync', 'facebook-for-woocommerce' ); ?> | ||
|
||
<?php if ( facebook_for_woocommerce()->get_connection_handler()->is_connected() ) : ?> | ||
<?php if ( $show_sync_button ) : ?> |
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.
Hmm, maybe we should not hide the button, so it's clear to merchant why it's disabled! 🤔
@haszari - I have applied the proposed changes in #2036 (review) |
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.
Looks great to me - I think we can close the other PRs and do some more testing & get feedback on this approach & then release 🎉
Keen to get data on what the impact of the threshold is on the database option size - can you run some tests and add the info to this PR? E.g. for 500 products, 1000, 2500, 5000.
Also please refresh the PR description to match the latest changes (or remind me – I can do tomorrow).
facebook-commerce.php
Outdated
* @var int Maximum number of products for full sync. | ||
* Used to disable full batch-API sync flows which may cause performance issues. | ||
**/ | ||
const MAX_PRODUCTS_FOR_FULL_SYNC = 500; |
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 bump this up to 5k - that's approx a quarter of the 19k from the problematic site, and host/site can use the filter if they need a smaller threshold.
facebook-commerce.php
Outdated
* @var int Maximum number of products for full sync. | ||
* Used to disable full batch-API sync flows which may cause performance issues. | ||
**/ | ||
const MAX_PRODUCTS_FOR_FULL_SYNC = 500; |
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.
(And let's test it - how big is the option with 5000 products?)
includes/AJAX.php
Outdated
@@ -214,6 +214,11 @@ public function admin_complete_order() { | |||
* @since 2.0.0 | |||
*/ | |||
public function sync_products() { | |||
// Inhibit on-demand full batch-api sync if the store has large product count. |
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 tweak these comments, as this could be disabled based on various factors now that it's an opt-out hook.
E.g. Allow opt-out of full batch-API sync, for example if store has a large number of products
.
includes/Handlers/Connection.php
Outdated
@@ -301,7 +301,10 @@ public function handle_connect() { | |||
$this->update_system_user_id( $system_user_id ); | |||
$this->update_installation_data(); | |||
|
|||
facebook_for_woocommerce()->get_products_sync_handler()->create_or_update_all_products(); | |||
// Only trigger initial full batch-api sync if the store doesn't have large product count. |
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.
Likewise for this comment 👯
…-large-stores * release-2.6.1: add 2.6.1 changelog entries run phpcs npm script silently, so xml output isn't broken by command echo add phpcs reminder to PR template get phpcs passing in GitHub action: - add explicit pr command targeting only php files (was hitting js files) - use in action yml script un-ignore phpcs and fix phpcs issues add phpcs:ignoreFile comment to all unhappy files
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 is looking splendid - thanks @rcstr . I've added some more comments and also updated the description. Thanks for proactively sorting out the changelog!
I'm still testing (in conjunction with a PR using the filter), but 🤞 this PR is ready to go.
- the reported issue may not affect all platforms / merchants - this reduces the chance of the disable impacting sites that rely on full sync
Update: I've reworked this so it just provides the filter. By default, no behaviour will change. Explaining the rationale for this:
|
- no longer opting out by default - add rationale & context to hook changelog
Update: tweaked the error message for the AJAX full sync - now just says the sync was disabled via filter (may not be due to product count). |
I've tested this with and without a custom filter and confirmed it allows disabling of the two relevant full sync operations. I've added some more logging and tweaked the messages so it's clear that this was disabled via a customization. Merging - and proceeding to release 2.6.1! |
Merge pull request #2033 from woocommerce/fix/disable-full-batch-api-sync-for-large-stores Add hook to allow disable of full batch api sync (e.g. for large stores) to avoid potential performance issues
Fixes #2022, #2035
See also related #2023 #2025 #2029
phpcs
checks? Please removephpcs:ignore
comments in changed files and fix any issues, or delete if not practical.Changes proposed in this Pull Request:
This PR provides a hook to allow developers (or hosting platforms) to disable specific full-catalog sync operations (via Batch API). See below
Why?
for more background and context.Specifically these two flows are affected:
Marketing > Facebook > Product sync
. If full batch API sync is disabled via filter, an error will be shown.The default behaviour is that the full batch-api background sync is allowed (consistent with previous releases).
Some example use-cases for the hook.
Example use of hook:
Also in this PR the
get_product_count()
function has been optimised to usewp_count_posts
. We're passing the total number of products to the hook. The previous query was loading all the IDs into memory, which is unnecessary and could impact performance for larger stores.Why?
A full catalog sync using the batch API and the
Products\Sync\Background
task can cause issues.The
Background
class uses theSkyVerge
background job framework. This adds an option to the database representing the job status and progress, which includes all product IDs that are included in the sync job.There are two risks with this:
Long term, we may need to tweak or replace the
Products\Sync\Background
so we have a scalable, robust way to sync full catalog. This is a medium-term patch to prevent this sync mechanism causing issues for merchants and web hosts, and to give more control over whether full batch sync happens.How does this impact stores, and the product sync feature?
Does this solve the issue?
It may be still possible to trigger a similar problem via code or API (or UI!), by marking a large number of products as needing sync (e.g. make a trivial edit). This PR doesn't fix the root of the problem (
Products\Sync\Background
scalability). One potential workaround: #2034How to test the changes in this Pull Request:
Add a filter for
facebook_for_woocommerce_allow_full_batch_api_sync
to disable full sync, e.g. for sites with > 5000 products.Two main flows to test:
Test to ensure the filter disables full sync appropriately.
Changelog entry