I was doing some profiling on Xcart and discovered that insert_productsonline() can take upwards of 15,000 milliseconds to execute, making up about 60% of the shopping cart's resource usage. This happens when MySQL hasn't stored and optimized the query for future use. Most of the time the calling of this function takes an average of 740 ms and about 11% of the shopping cart's execution time & resource usage.
I have found a simple remedy to this problem that produces the same results as the original code, but uses up only an average of 120 ms.
Note that our site holds over 65,000 products, so it is no wonder this takes up a lot of processing power to gather the statistics.
Replace the
return line in
insert_productsonline() in
include/func.php with the following code:
Code:
return func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[products], $sql_tbl[categories] WHERE $sql_tbl[products].forsale='Y' AND $sql_tbl[products].categoryid=$sql_tbl[categories].categoryid AND ($sql_tbl[categories].membership='$user_account[membership]' OR $sql_tbl[categories].membership='')");
The key to this code speed increase is the usage of
COUNT(*) instead of
COUNT($sql_tbl[products].productid).
Please note that your must be using a version of Xcart that has the func_query_first_cell() function available. If not, then simply use array_pop(func_query_first()) in its place.