WooCommerce Scheduled Actions Killing Performance? Here’s How To Check
WooCommerce relies heavily on a background task system called"action scheduler". These actions are background jobs used by WooCommerce and WooCommerce extension plugins to run tasks asynchronously.
A good example of this is when a customer purchases a product, scheduled actions are added to reduce the stock number of that product, send the customer a purchase completion email, and send the website owner an email to let them know there has been a purchase. These are just some of many examples of when scheduled actions are used.
When a WooCommerce website is created, the Action Scheduler creates these tables by default:
wp_actionscheduler_actionswp_actionscheduler_logswp_actionscheduler_groupswp_actionscheduler_claims
These are usually manageable on smaller websites – However, on more active or older sites, this system is one of the most common (but least obvious) causes of database bloat, which can lead to slow admin pages and website timeouts – which can have a negative impact on customers, sales, and overall website SEO.
How Do Scheduled Actions Hurt Performance?
Every action – completed, failed, or pending – is stored in the database. This can lead to numerous scenarios which can cause performance problems – most commonly, completed actions building up and not getting cleaned up, or failed actions retrying endlessly.
I’ve seen clients with millions of these actions – and cleaning them up can have an almost instant impact on performance, for both the developers or website admins – and for the customer.
How To Clean Up Scheduled Actions:
WooCommerce does provide an automatic cleanup periodically (every 30 days), but this is generally slow on larger tables, it can often timeout – and if it times-out, doesn’t always remove the logs effectively, adding to the overall problem.
Here is how to clean the tables up in SQL:
DISCLAIMER : PLEASE TAKE A BACKUP BEFORE RUNNING ANY SQL QUERY LIKE THIS. JUST BECAUSE THIS QUERY WORKED FOR ME, DOESN’T GUARANTEE IT WILL WORK FOR YOU, AND I ACCEPT NO RESPONSIBILITY FOR DATA LOSS.
DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'canceled';
DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'failed';
DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'complete';
These are safe queries to run on canceled, failed and complete actions – as you probably won’t need to reference them again.
The query can also be run on pending actions, but this should be done with caution – as it would stop any pending tasks from being run, some of which might be needed and would not be automatically recreated – scheduled payments are a good example of this.
If you have a very busy store, you can also change WooCommerce’s default cleanup from 30 days to run every 7 days (or a period of time of your choosing). To do this, place this function in your functions.php file:
add_filter( 'action_scheduler_retention_period', 'wpb_action_scheduler_purge' );
function wpb_action_scheduler_purge() {
return WEEK_IN_SECONDS;
}
This is the sort of thing my care plans handle each month.
Related guides
Want this handled for you?
I do this for clients every day. Get my free audit and I’ll tell you exactly what’s worth fixing on your site.