Repository Forums Support WooCommerce Extended Coupon Features PRO slow calculate_totals() – tips? Reply To: slow calculate_totals() – tips?

#3190
Soft79
Keymaster

The 100s of milliseconds is just not right. Measuring on my system the call is never more than 4 ms. That’s why I ask you for a further drilldown of get_all_auto_coupons() and coupon_can_be_applied().

Those two methods don’t do a lot of work, but they can create a new instance of WC_Coupon. So, possibly another hook (from a different plugin) is fired which slows things down. Is your database on a local server or remote? Can the database be the culprit?

This is part of the measurement on my system:


Elapsed in get_all_auto_coupons: 0.382261 - 0.380914 = 0.001347 sec
Elapsed in get_all_auto_coupons: 0.384839 - 0.382290 = 0.002549 sec
Elapsed in get_all_auto_coupons: 0.385457 - 0.385452 = 0.000005 sec
Elapsed in get_all_auto_coupons: 0.412427 - 0.412420 = 0.000007 sec
Elapsed in get_all_auto_coupons: 0.418027 - 0.412456 = 0.005571 sec
Elapsed in get_all_auto_coupons: 0.418671 - 0.418666 = 0.000005 sec
Elapsed in get_all_auto_coupons: 0.465769 - 0.465758 = 0.000011 sec
Elapsed in get_all_auto_coupons: 0.470228 - 0.465832 = 0.004396 sec
Elapsed in get_all_auto_coupons: 0.471185 - 0.471180 = 0.000005 sec

Changing the hooks used by the plugin is a risky operation with 10.000’s of installations; I do have plans on changing this but it will probably be in a 3.0 release.