From cebd95901d2e4e168c448b4a1ac0c2ad794b84b0 Mon Sep 17 00:00:00 2001 From: rGaillard Date: Tue, 29 May 2012 08:32:13 +0000 Subject: [PATCH] // Performance optimizations --- classes/Cart.php | 9 ++++++--- classes/Combination.php | 6 +++++- classes/Link.php | 10 +++++++--- classes/Product.php | 14 +++++++++----- classes/SpecificPrice.php | 6 +++++- classes/Tools.php | 13 +++++++++++-- classes/tax/Tax.php | 6 +++++- 7 files changed, 48 insertions(+), 16 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index 1c8a5a633..316f2508c 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1799,8 +1799,8 @@ class CartCore extends ObjectModel */ public function getDeliveryOptionList(Country $default_country = null, $flush = false) { - static $cache = false; - if ($cache !== false && !$flush) + static $cache = null; + if ($cache !== null && !$flush) return $cache; $delivery_option_list = array(); @@ -1828,7 +1828,10 @@ class CartCore extends ObjectModel { // No carriers available if (count($package['carrier_list']) == 1 && current($package['carrier_list']) == 0) - return array(); + { + $cache = array(); + return $cache; + } $carriers_price[$id_address][$id_package] = array(); diff --git a/classes/Combination.php b/classes/Combination.php index a1f4e288c..07c0755b7 100644 --- a/classes/Combination.php +++ b/classes/Combination.php @@ -200,7 +200,11 @@ class CombinationCore extends ObjectModel */ public static function isFeatureActive() { - return Configuration::get('PS_COMBINATION_FEATURE_ACTIVE'); + static $feature_active = null; + + if ($feature_active === null) + $feature_active = Configuration::get('PS_COMBINATION_FEATURE_ACTIVE'); + return $feature_active; } /** diff --git a/classes/Link.php b/classes/Link.php index 4ffd496f4..2f24df64e 100644 --- a/classes/Link.php +++ b/classes/Link.php @@ -35,6 +35,8 @@ class LinkCore public $protocol_link; public $protocol_content; + protected $ssl_enable; + /** * Constructor (initialization only) */ @@ -49,6 +51,8 @@ class LinkCore define('_PS_BASE_URL_', Tools::getShopDomain(true)); if (!defined('_PS_BASE_URL_SSL_')) define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true)); + + $this->ssl_enable = Configuration::get('PS_SSL_ENABLED'); } /** @@ -209,7 +213,7 @@ class LinkCore */ public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = null) { - $base = (($ssl && Configuration::get('PS_SSL_ENABLED')) ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_); + $base = (($ssl && $this->ssl_enable) ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_); if (!$id_lang) $id_lang = Context::getContext()->language->id; @@ -301,7 +305,7 @@ class LinkCore */ public function getModuleLink($module, $controller = 'default', array $params = array(), $ssl = false, $id_lang = null) { - $base = (($ssl && Configuration::get('PS_SSL_ENABLED')) ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_); + $base = (($ssl && $this->ssl_enable) ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_); if (!$id_lang) $id_lang = Context::getContext()->language->id; @@ -401,7 +405,7 @@ class LinkCore unset($request['controller']); $uri_path = Dispatcher::getInstance()->createUrl($controller, $request); - $url = ($ssl && Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true); + $url = ($ssl && $this->ssl_enable) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true); $url .= __PS_BASE_URI__.$this->getLangLink($id_lang).ltrim($uri_path, '/'); return $url; diff --git a/classes/Product.php b/classes/Product.php index 9cade80ac..f43b6da21 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -2370,6 +2370,11 @@ class ProductCore extends ObjectModel $id_group, $quantity, $use_tax, $decimals, $only_reduc, $use_reduc, $with_ecotax, &$specific_price, $use_group_reduction, $id_customer = 0, $use_customer_price = true, $id_cart = 0) { + static $address = null; + + if ($address === null) + $address = new Address(); + if (!$use_customer_price) $id_customer = 0; @@ -2382,6 +2387,9 @@ class ProductCore extends ObjectModel '-'.$quantity.'-'.$product_attribute_label.'-'.($use_tax?'1':'0').'-'.$decimals.'-'.($only_reduc?'1':'0'). '-'.($use_reduc?'1':'0').'-'.$with_ecotax.'-'.$id_customer; + if (isset(self::$_prices[$cache_id])) + return self::$_prices[$cache_id]; + // reference parameter is filled before any returns $specific_price = SpecificPrice::getSpecificPrice( (int)$id_product, @@ -2395,9 +2403,6 @@ class ProductCore extends ObjectModel $id_cart ); - if (isset(self::$_prices[$cache_id])) - return self::$_prices[$cache_id]; - // fetch price & attribute price $cache_id_2 = $id_product.'-'.(int)$id_product_attribute; if (!isset(self::$_pricesLevel2[$cache_id_2])) @@ -2455,7 +2460,6 @@ class ProductCore extends ObjectModel } // Tax - $address = new Address(); $address->id_country = $id_country; $address->id_state = $id_state; $address->postcode = $zipcode; @@ -3448,7 +3452,7 @@ class ProductCore extends ObjectModel $usetax = Tax::excludeTaxeOption(); $cache_key = $row['id_product'].'-'.$row['id_product_attribute'].'-'.$id_lang.'-'.(int)$usetax; - if (array_key_exists($cache_key, self::$producPropertiesCache)) + if (isset(self::$producPropertiesCache[$cache_key])) return self::$producPropertiesCache[$cache_key]; // Datas diff --git a/classes/SpecificPrice.php b/classes/SpecificPrice.php index 977e1f936..8334e4781 100644 --- a/classes/SpecificPrice.php +++ b/classes/SpecificPrice.php @@ -395,7 +395,11 @@ class SpecificPriceCore extends ObjectModel */ public static function isFeatureActive() { - return Configuration::get('PS_SPECIFIC_PRICE_FEATURE_ACTIVE'); + static $feature_active = null; + + if ($feature_active === null) + $feature_active = Configuration::get('PS_SPECIFIC_PRICE_FEATURE_ACTIVE'); + return $feature_active; } public static function exists($id_product, $id_product_attribute, $id_shop, $id_group, $id_country, $id_currency, $id_customer, $from_quantity, $from, $to, $rule = false) diff --git a/classes/Tools.php b/classes/Tools.php index b2dacc7f6..1c2995d22 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -502,6 +502,11 @@ class ToolsCore */ public static function convertPrice($price, $currency = null, $to_currency = true, Context $context = null) { + static $default_currency = null; + + if ($default_currency === null) + $default_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT'); + if (!$context) $context = Context::getContext(); if ($currency === null) @@ -512,7 +517,7 @@ class ToolsCore $c_id = (is_array($currency) ? $currency['id_currency'] : $currency->id); $c_rate = (is_array($currency) ? $currency['conversion_rate'] : $currency->conversion_rate); - if ($c_id != (int)Configuration::get('PS_CURRENCY_DEFAULT')) + if ($c_id != $default_currency) { if ($to_currency) $price *= $c_rate; @@ -1139,7 +1144,11 @@ class ToolsCore */ public static function ps_round($value, $precision = 0) { - $method = (int)Configuration::get('PS_PRICE_ROUND_MODE'); + static $method = null; + + if ($method == null) + $method = (int)Configuration::get('PS_PRICE_ROUND_MODE'); + if ($method == PS_ROUND_UP) return Tools::ceilf($value, $precision); elseif ($method == PS_ROUND_DOWN) diff --git a/classes/tax/Tax.php b/classes/tax/Tax.php index d91e98a5f..cd5aaed26 100644 --- a/classes/tax/Tax.php +++ b/classes/tax/Tax.php @@ -163,7 +163,11 @@ class TaxCore extends ObjectModel public static function excludeTaxeOption() { - return !Configuration::get('PS_TAX'); + static $ps_tax = null; + if ($ps_tax === null) + $ps_tax = Configuration::get('PS_TAX'); + + return !$ps_tax; } /**