From 3d0ccb91eb14e12b3d7a6d6c3d1b90460a54bf3d Mon Sep 17 00:00:00 2001 From: rGaillard Date: Mon, 12 Mar 2012 14:50:56 +0000 Subject: [PATCH] // Improve performance --- classes/Address.php | 14 ++++++++------ classes/Hook.php | 5 ++--- classes/Product.php | 4 +++- classes/Translate.php | 7 ++++++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/classes/Address.php b/classes/Address.php index 4108bee85..6527375fe 100644 --- a/classes/Address.php +++ b/classes/Address.php @@ -293,12 +293,14 @@ class AddressCore extends ObjectModel */ public static function addressExists($id_address) { - $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' - SELECT `id_address` - FROM '._DB_PREFIX_.'address a - WHERE a.`id_address` = '.(int)$id_address); - - return isset($row['id_address']); + $key = 'address_exists_'.(int)$id_address; + if (!Cache::isStored($key)) + Cache::store( + $key, Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' + SELECT `id_address` + FROM '._DB_PREFIX_.'address a + WHERE a.`id_address` = '.(int)$id_address)); + return Cache::retrieve($key); } public static function getFirstCustomerAddressId($id_customer, $active = true) diff --git a/classes/Hook.php b/classes/Hook.php index 436b015fe..94e8ee46a 100644 --- a/classes/Hook.php +++ b/classes/Hook.php @@ -368,10 +368,9 @@ class HookCore extends ObjectModel // Call hook method if ($hook_callable) - $display = call_user_func(array($moduleInstance, 'hook'.$hook_name), $hookArgs); + $display = $moduleInstance->{'hook'.$hook_name}($hookArgs); else if ($hook_retro_callable) - $display = call_user_func(array($moduleInstance, 'hook'.$retro_hook_name), $hookArgs); - + $display = $moduleInstance->{'hook'.$retro_hook_name}($hookArgs); // Live edit if ($array['live_edit'] && ((Tools::isSubmit('live_edit') && Tools::getValue('ad') && (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_))))) { diff --git a/classes/Product.php b/classes/Product.php index 08f84e98c..c1b1cbe54 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3448,7 +3448,9 @@ class ProductCore extends ObjectModel { if (!$row['id_product']) return false; - $context = Context::getContext(); + + if ($context == null) + $context = Context::getContext(); // Product::getDefaultAttribute is only called if id_product_attribute is missing from the SQL query at the origin of it: // consider adding it in order to avoid unnecessary queries diff --git a/classes/Translate.php b/classes/Translate.php index 020abc22b..94f766e6f 100644 --- a/classes/Translate.php +++ b/classes/Translate.php @@ -115,6 +115,7 @@ class TranslateCore { global $_MODULES, $_MODULE, $_LANGADM; static $lang_cache = array(); + static $translations_merged = array(); if ($module instanceof Module) { @@ -134,7 +135,11 @@ class TranslateCore $file = $local_path.'/'.Context::getContext()->language->iso_code.'.php'; if (Tools::file_exists_cache($file) && include_once($file)) - $_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE; + { + if (!isset($translations_merged[md5($file)])) + $_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE; + $translations_merged[md5($file)] = true; + } $string = str_replace('\'', '\\\'', $string);