Suggested patch for perf and plugin compatibility
-
I would like to suggest a set of patches for this plugin. I couldn’t find a Github repo associated to this plugin so I’m just providing a Github Gist with two patch files. If there is a better way to provide this feedback please let me know.
https://gist.github.com/shaunek-hero/e58a67e977b136e3d2572ad1fc5cf63d
Summary: This patch changes the plugin code to call
$order->save_meta_data()
instead of$order->save()
wherever practical.Rationale:
- This could be considered a performance enhancement since calling
save_meta_data()
does a lot less work compared tosave()
- Since these calls to
save()
seem to be targeted at saving order meta data only, it might be good to reduce the number of woocommerce hooks that get invoked as a result, which may cause fewer bugs in other plugins and themes.
In my case, I found that the calls to?
$order->save()
?in this plugin were interacting with another of my plugins – my other plugin had a very poorly coded callback for the?woocommerce_after_order_object_save
?hook, which, as the name implies, runs every time?$order->save()
?is invoked. Since it is a private plugin I can’t share the actual code, but I’ll just say that the callback in my other plugin was doing some special inventory modifications in certain cases. I have observed a few cases where a brand new order was created (customer checked out) and at the same moment the?woocommerce-shipstation-integration
?plugin’s export process ran and since the export calls?$order-save()
?there was a race condition (due to my poorly coded plugin) and the special inventory modifications were performed twice. This is a relatively rare race condition, but I consider it a pretty serious bug in my plugin. Make no mistake, I fully understand that the bulk of the reason for the race condition was due to my poorly coded plugin, and I have made a substantial improvement to my plugin such that this race condition will be very unlikely in the future. However, I got to thinking that if the?woocommerce-shipstation-integration
?plugin didn’t even call?$order->save()
?my painful bug wouldn’t have happened, or at least it wouldn’t have happened due to?woocommerce-shipstation-integration
??? And then I got to thinking, I wonder how many other Woocommerce customers there are that have some poorly coded plugin or theme that could interact poorly with this as well, so I decided to make this suggestion. - This could be considered a performance enhancement since calling
- The topic ‘Suggested patch for perf and plugin compatibility’ is closed to new replies.