1.2M products: Optimizing the product update journey in WP Admin

After generating 1.2M products and variations, the shop still runs very smooth in frontend!

Though, we noticed a problem in backend. Product creation or updating in WP Admin took a very long time (about 25 seconds). Initially, we thought the issue might be related to ElasticPress, suspecting that the synchronization between WP and EP was taking too much time. However, even after disabling the EP plugin, there were no improvements.

To identify the root cause of the slowdown, we utilized Xdebug Profiler and gained a clear understanding of the problem. It turned out that the wp_update_term_count() function was taking a significant amount of time, specifically 11 seconds. This finding was not surprising considering we had 298 categories and 7,884 tags.

Upon examining the code, we discovered two hooks where the mentioned function or related processes were being executed:
transition_post_status – This action was fired even if the post status remained unchanged.
woocommerce_product_recount_terms – This filter served as a flag to disable term count recalculation, but unfortunately, it didn’t disable it completely.

To address the issue, we decided to disable term recalculation during the Woocommerce product update entirely. Initially, we set the “woocommerce_product_recount_terms” filter to “false,” but it didn’t yield the desired results. As the next step, we removed the “_update_term_count_on_transition_post_status” function from the “transition_post_status” action. However, we took care not to affect other post types, so we re-created the function with a condition to skip Woocommerce product post types.

Although the Profiler indicated an 11-second improvement, we experienced an almost 20-second improvement during the Woocommerce product update. It’s possible that there were other areas in the code where similar processes were executed, but they took less time and weren’t noticeable in the profiling. As of now, the update process takes around 6-7 seconds, but there is still room for further optimization.

Furthermore, we didn’t overlook the importance of terms counts. We implemented a CRON task to recalculate all terms hourly, which means there might be a slight delay until the numbers are updated. However, this approach ensures that the dashboard remains usable, as most users wouldn’t tolerate a 25-second wait when updating a product.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top