From b8cc96dbb91702c37fdab03f04bd545ce8d2bf79 Mon Sep 17 00:00:00 2001 From: fBrignoli Date: Tue, 3 Apr 2012 08:39:42 +0000 Subject: [PATCH] // cache system on getIsoById --- classes/Country.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/classes/Country.php b/classes/Country.php index 37cabf7b5..ecee0fcd8 100644 --- a/classes/Country.php +++ b/classes/Country.php @@ -92,6 +92,8 @@ class CountryCore extends ObjectModel ) ); + protected static $cache_iso_by_id = array(); + protected $webserviceParameters = array( 'objectsNodeName' => 'countries', 'fields' => array( @@ -208,13 +210,15 @@ class CountryCore extends ObjectModel */ public static function getIsoById($id_country) { - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' - SELECT `iso_code` - FROM `'._DB_PREFIX_.'country` - WHERE `id_country` = '.(int)$id_country - ); + if (!isset(Country::$cache_iso_by_id[$id_country])) + { + Country::$cache_iso_by_id[$id_country] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + SELECT `iso_code` + FROM `'._DB_PREFIX_.'country` + WHERE `id_country` = '.(int)($id_country)); + } - return $result['iso_code']; + return Country::$cache_iso_by_id[$id_country]; } /**