Hi David, hope all is well!
Not sure if you remember, but I had performance issues on my site that turned out to be a poorly formed script on the page (nothing to do with PT at all!).
Search results pages are quite speedy now (removed the problem script!), but I'm noticing a real lag in product pages.
Can you point me a direction to troubleshoot? I'm not sure if the products access the database different from the search page. They share the same header/footer so I know that's not the problem. I've even tried disabling related products, but that didn't make a difference.
Thanks!
T.
Hi David, I had updated the original post to include the snippet that caused the problem (was able to isolate!). I had copied some code to manage a "views" table from another thread.
It could be my host php/mySQL configuraion, but I had to remove this from products.php:
if ($q)
$sql = "UPDATE `".$config_databaseTablePrefix."products` SET views = views + 1 WHERE name = '".database_safe($q)."'";
database_queryModify($sql,$insertID);
$result = mysql_query("SELECT product_name FROM views WHERE product_name='".database_safe($q)."'");
$num = mysql_num_rows($result);
if(empty($num)) {
$sql = "INSERT INTO views SET product_name='".database_safe($q)."', merchant='".$product["products"][0]["merchant"]."', view='1'";
database_queryModify($sql,$insertID);
}
else {
$sql = "UPDATE views SET view=view+1 WHERE product_name='".database_safe($q)."' AND merchant='".$product["products"][0]["merchant"]."'";
database_queryModify($sql,$insertID);
If you have any suggestions, that would be great.
Thanks!
T.
Hi,
Couple of comments...
Firstly; as you have a dedicated `views` table; is it still necessary to increment the views field in the `products` table?
And perhaps more crucially; is the `product_name` field in your `views` table indexed - that would make a big difference to performance if it is not. Finally, you could also add LIMIT 1 to the query as there will only ever be one row to update by definition; so this will save the database from scanning the entire table:
$sql = "UPDATE views SET view=view+1 WHERE product_name='".database_safe($q)."' AND merchant='".$product["products"][0]["merchant"]."' LIMIT 1";
Hope this helps!
Cheers,
David.
Hi,
Could you email me a link to an example product page and I'll take a look...
Cheers,
David.