Making the WPNotif plugin faster

Dave Hilditch
Talk to me

A customer of mine was struggling with an import. After activating the Slow Query Log inside Scalability Pro I discovered they had a slow query coming from a plugin called WPNotif. This plugin is sold by Code Canyon and lets you send WhatsApp messages to your customers – quite cool!

Settings page Scalability Pro to access the Slow Query Log
Scalability Pro’s Slow Query Log Settings

They have a slow query however which you won’t notice at first, but once your site gets larger you’ll notice a big slowdown which hurts your server.

Slow query from WPNotif up top

WPNotif’s table structure

They create a table called wpnotif_wc_cart_sessions. This table comes with 2 indexes by default but no index for the slow query we discovered.

Two default indexes, without an index for the slow query

Adding a suitable index for making the WPNotif plugin faster

The slow query is doing an equals operation on the notif_status column and a less-than operation on the time column. When it comes to matching indexes up to queries, the order of the columns in the indexes matters. Basically – any columns where the query performs an equals operation should come first in the index with greater-than and less-than columns coming at the end of the index.

MySQL will benefit from an index when performing a less-than or greater-than operation but it can only really optimise ONE of these operations in the query. After that, the remaining data needs to be scanned.

So – that means our index should be on notif_status and then time.

Super speedy query

Now the query takes 0.001s instead of 0.329s. Note this would only have gotten worse for this customer – the more customers and cart sessions they had, the slower their website and notifications service would have become.

Be the first to comment and we'll reply right away.

Leave a reply

Super Speedy Plugins
Logo