View Single Post
  #1  
Old 01-19-2005, 07:34 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default Speed up Smarty templates by taking out {math} functions

To get more speed out of your templates, remove the {math} function from your product.tpl template (and others) to PHP. I will cover product.tpl, but any other template that uses {math} will also benefit if you do likewise (such as products.tpl or products_t.tpl). The {math} function is eval()'d each time it is called and is extremely slow. Some usages of the {math} function can be over 450% slower than doing the same in native PHP code.

Find the function func_select_product in func.php and add this to the $product = func_query_first( SQL statement to replace the 'savings' and 'discount' math calculations:
Code:
100-($sql_tbl[pricing].price/$sql_tbl[products].list_price)*100 AS discount, $sql_tbl[products].list_price-$sql_tbl[pricing].price AS savings,

Below the select statement, add the following to replace the 'mq' math calculation:
Code:
if ($product) { if ($config['General']['unlimited_products'] == 'Y') $product['min_quantity'] = $config['Appearance']['max_select_quantity']+1; else { $tmp_compare = $config['Appearance']['max_select_quantity']/$product['min_amount']; if ($tmp_compare < 2) $minamount = $product['min_amount']; else $minamount = 0; $product['min_quantity'] = min($config['Appearance']['max_select_quantity']+$minamount, $product['avail'])+1; } }

In product.tpl:
Find your $discount and change it to:$product.discount|string_format:'%d'

Find $savings and change it to: $product.savings|string_format:'%f'

Find the {section} loop that uses $mq and change it to: $product.min_quantity

Lastly, go back and comment out all of the code in product.tpl that originally calculated these values by enclosing them in {* and *}.

If everything looks as it should when you load a product, then you can delete that template code you commented out if you'd like.

I cannot remember if there are any other {math} functions in product.tpl, as that was one speed issue I jumped at early on.

If anyone feels like posting their success with this or other templates and how you did it, don't hesitate to let everyone know. I'd love to be able to post steps for the rest of the templates I know but current time constraints won't allow for it.
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote