From 68264668ac0c88a06b24e931c43125588d4966e5 Mon Sep 17 00:00:00 2001 From: Lubos Hubacek Date: Thu, 8 Oct 2020 00:08:37 +0200 Subject: [PATCH 1/5] Caching currencies --- .../Directory/Model/Resource/Currency.php | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/app/code/core/Mage/Directory/Model/Resource/Currency.php b/app/code/core/Mage/Directory/Model/Resource/Currency.php index 15507d8cfe7..97fd73dc2fc 100644 --- a/app/code/core/Mage/Directory/Model/Resource/Currency.php +++ b/app/code/core/Mage/Directory/Model/Resource/Currency.php @@ -48,6 +48,12 @@ class Mage_Directory_Model_Resource_Currency extends Mage_Core_Model_Resource_Db */ protected static $_rateCache; + /** + * All allowed currencies cache + * @var array + */ + protected $_configCurrencies; + /** * Define main and currency rate tables * @@ -183,19 +189,23 @@ public function saveRates($rates) */ public function getConfigCurrencies($model, $path) { - $adapter = $this->_getReadAdapter(); - $bind = array(':config_path' => $path); - $select = $adapter->select() + if ($this->_configCurrencies == null) { + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() ->from($this->getTable('core/config_data')) ->where('path = :config_path'); - $result = array(); - $rowSet = $adapter->fetchAll($select, $bind); - foreach ($rowSet as $row) { - $result = array_merge($result, explode(',', $row['value'])); + + $result = array(); + $rowSet = $adapter->fetchAll($select, [':config_path' => $path]); + foreach ($rowSet as $row) { + $result = array_merge($result, explode(',', trim($row['value']))); + } + sort($result); + + $this->_configCurrencies = array_unique($result); } - sort($result); - return array_unique($result); + return $this->_configCurrencies; } /** From f706c663e33493831318a8ed3c0875ccf2e0fcaa Mon Sep 17 00:00:00 2001 From: Lubos Hubacek Date: Thu, 8 Oct 2020 00:21:24 +0200 Subject: [PATCH 2/5] Caching currencies - base --- app/code/core/Mage/Directory/Model/Currency.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/Directory/Model/Currency.php b/app/code/core/Mage/Directory/Model/Currency.php index 8dbb3ec4bd5..1186a197858 100644 --- a/app/code/core/Mage/Directory/Model/Currency.php +++ b/app/code/core/Mage/Directory/Model/Currency.php @@ -333,8 +333,8 @@ public function getConfigDefaultCurrencies() */ public function getConfigBaseCurrencies() { - $defaultCurrencies = $this->_getResource()->getConfigCurrencies($this, self::XML_PATH_CURRENCY_BASE); - return $defaultCurrencies; + $defaultCurrencies = (string) Mage::app()->getConfig()->getNode(self::XML_PATH_CURRENCY_BASE, 'default'); + return [$defaultCurrencies]; } /** From fa9ce02a4e89471137394e39b622c5e36e46086d Mon Sep 17 00:00:00 2001 From: Lubos Hubacek Date: Fri, 16 Oct 2020 14:39:22 +0200 Subject: [PATCH 3/5] Fix currency load - without additional SQL queries --- .../Directory/Model/Resource/Currency.php | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/app/code/core/Mage/Directory/Model/Resource/Currency.php b/app/code/core/Mage/Directory/Model/Resource/Currency.php index 97fd73dc2fc..623fcf84180 100644 --- a/app/code/core/Mage/Directory/Model/Resource/Currency.php +++ b/app/code/core/Mage/Directory/Model/Resource/Currency.php @@ -48,12 +48,6 @@ class Mage_Directory_Model_Resource_Currency extends Mage_Core_Model_Resource_Db */ protected static $_rateCache; - /** - * All allowed currencies cache - * @var array - */ - protected $_configCurrencies; - /** * Define main and currency rate tables * @@ -189,22 +183,24 @@ public function saveRates($rates) */ public function getConfigCurrencies($model, $path) { - if ($this->_configCurrencies == null) { - $adapter = $this->_getReadAdapter(); - $select = $adapter->select() - ->from($this->getTable('core/config_data')) - ->where('path = :config_path'); + $result = []; + $config = Mage::app()->getConfig(); - $result = array(); - $rowSet = $adapter->fetchAll($select, [':config_path' => $path]); - foreach ($rowSet as $row) { - $result = array_merge($result, explode(',', trim($row['value']))); - } - sort($result); + // default + $result = array_merge($result, explode(',', trim($config->getNode($path, 'default')))); - $this->_configCurrencies = array_unique($result); + // stores + foreach (Mage::app()->getStores(true) as $store) { + $result = array_merge($result, explode(',', trim($config->getNode($path, 'stores', $store->getCode())))); } + // websites + foreach (Mage::app()->getWebsites(true) as $website) { + $result = array_merge($result, explode(',', trim($config->getNode($path, 'websites', $website->getCode())))); + } + + sort($result); + return $this->_configCurrencies; } From fdd7d9b949aa37e51e2f9c30883d142a2f4b9cb3 Mon Sep 17 00:00:00 2001 From: Lubos Hubacek Date: Fri, 16 Oct 2020 14:41:21 +0200 Subject: [PATCH 4/5] Fix currency load - without additional SQL queries --- app/code/core/Mage/Directory/Model/Currency.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/Directory/Model/Currency.php b/app/code/core/Mage/Directory/Model/Currency.php index 1186a197858..8dbb3ec4bd5 100644 --- a/app/code/core/Mage/Directory/Model/Currency.php +++ b/app/code/core/Mage/Directory/Model/Currency.php @@ -333,8 +333,8 @@ public function getConfigDefaultCurrencies() */ public function getConfigBaseCurrencies() { - $defaultCurrencies = (string) Mage::app()->getConfig()->getNode(self::XML_PATH_CURRENCY_BASE, 'default'); - return [$defaultCurrencies]; + $defaultCurrencies = $this->_getResource()->getConfigCurrencies($this, self::XML_PATH_CURRENCY_BASE); + return $defaultCurrencies; } /** From f1d734500c0514f583da12c13ab07cd72b2adb76 Mon Sep 17 00:00:00 2001 From: Lubos Hubacek Date: Fri, 16 Oct 2020 14:42:05 +0200 Subject: [PATCH 5/5] Fix currency load - without additional SQL queries --- app/code/core/Mage/Directory/Model/Resource/Currency.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Directory/Model/Resource/Currency.php b/app/code/core/Mage/Directory/Model/Resource/Currency.php index 623fcf84180..fb3d79176b2 100644 --- a/app/code/core/Mage/Directory/Model/Resource/Currency.php +++ b/app/code/core/Mage/Directory/Model/Resource/Currency.php @@ -201,7 +201,7 @@ public function getConfigCurrencies($model, $path) sort($result); - return $this->_configCurrencies; + return array_unique($result); } /**