Dear Spoki Support and Development Team,
My name is Marco Marcoaldi, and I am the CTO of Managed Server SRL, a company specializing in advanced hosting and system administration with a strong focus on web platform performance. During the Black Friday event, we observed a significant increase in load on a client’s WooCommerce site, which led us to identify an optimization opportunity within the SPOKI plugin.Issue Observed
While analyzing SQL queries, we identified a repetitive and resource-intensive query generated by the init_tables()
function in the SPOKI plugin.
Specifically, the query:
SELECT COUNT(*) FROM wp_spoki_setting
located in /wp-content/plugins/spoki/modules/abandoned-carts/spoki-abandoned-carts-db.php
under the following code snippet:
public function init_tables()
{
global $wpdb;
$spoki_setting_tb = $wpdb->prefix . SPOKI_SETTING_TABLE;
if ($wpdb->get_var("SHOW TABLES LIKE '$spoki_setting_tb'") !== $spoki_setting_tb) {
error_log('Error: Table does not exist: ' . $spoki_setting_tb);
return;
}
$meta_count = $wpdb->get_var("SELECT COUNT(*) FROM $spoki_setting_tb");
if ((!$meta_count)) {
$env_file_path = SPOKI_DIR . '/.env';
if (file_exists($env_file_path)) {
$meta_data = parse_ini_file($env_file_path);
if ($meta_data === false) {
error_log('Error: Failed to parse .env file at ' . $env_file_path);
return;
}
$meta_data["access_token"] = md5(uniqid(wp_rand(), true));
foreach ($meta_data as $meta_key => $meta_value) {
$wpdb->insert(
$spoki_setting_tb,
array('meta_key' => $meta_key, 'meta_value' => $meta_value),
array('%s', '%s')
);
}
} else {
error_log('Warning: .env file not found at ' . $env_file_path);
}
}
}
This line in particular:
$meta_count = $wpdb->get_var("SELECT COUNT(*) FROM $spoki_setting_tb");
Performance Impact
Running this query on a table with approximately 14 million records took around 1 second per execution. Due to the frequency of this call, server load quickly rose to an average of 9, causing significant impact on overall system performance.
Proposed Optimization
The purpose of the query is simply to check for the presence of data in the table, rather than to count all records. To optimize, we modified the function as follows:
$meta_count = $wpdb->get_var("SELECT 1 FROM $spoki_setting_tb LIMIT 1");
This adjustment checks for any existing record in a more efficient manner, reducing execution time to mere milliseconds, and making the query highly cacheable.
Results
After implementing this optimization, we observed a reduction in average server load from 9 to 1.4, with noticeable improvements in overall system performance.
A differential analysis of the original and optimized queries confirmed that the original query was a significant contributor to CPU load.
Recommendation
We recommend integrating this adjustment into the SPOKI plugin code. This change can significantly benefit high-traffic environments, especially during peak periods such as Black Friday, by reducing database load and enhancing the responsiveness of WooCommerce platforms using SPOKI.
Thank you for considering this optimization suggestion. We would be happy to assist with further testing or provide additional insights as needed.
Best regards,
Marco Marcoaldi
CTO, Managed Server SRL
about your plugin, is it free or does it have any limitations?
]]>Does this plugin send notification to shop owner or merchant? This is also important because shop owner may miss any order.
]]>Hi,
I’m having problems with the plugin on my website. The floating button works fine, but the woocommerce notifications are not.
Can anybody help me?
With spoki I added whatsapp to my e-commerce in a moment!
]]>