Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F803817
D448.id1154.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 26, 8:58 AM
Size
1 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 8:58 AM (10 h, 34 m)
Engine
blob
Format
Raw Data
Handle
576541
Attached To
D448: INP-1843 - Cache results of the "kCountryStatesHelper::getCountryIso" method
D448.id1154.diff
View Options
Index: core/units/helpers/country_states_helper.php
===================================================================
--- core/units/helpers/country_states_helper.php
+++ core/units/helpers/country_states_helper.php
@@ -224,23 +224,25 @@
/**
* Returns 3 symbols ISO code from 2 symbols ISO code or otherwise, when $from_short parameter is used
*
- * @param string $iso_code
- * @param bool $from_short
+ * @param string $iso_code ISO code.
+ * @param boolean $from_short From short.
+ *
* @return string
*/
- function getCountryIso($iso_code, $from_short = false)
+ public function getCountryIso($iso_code, $from_short = false)
{
- if ($from_short) {
- $sql = 'SELECT IsoCode
- FROM ' . TABLE_PREFIX . 'CountryStates
- WHERE ShortIsoCode = ' . $this->Conn->qstr($iso_code) . ' AND `Type` = ' . DESTINATION_TYPE_COUNTRY;
- }
- else {
- $sql = 'SELECT ShortIsoCode
+ $cache_key = 'country_iso_mapping[%CountryStateSerial%]';
+ $cache_value = $this->Application->getCache($cache_key);
+
+ if ( $cache_value === false ) {
+ $sql = 'SELECT IsoCode, ShortIsoCode
FROM ' . TABLE_PREFIX . 'CountryStates
- WHERE IsoCode = ' . $this->Conn->qstr($iso_code) . ' AND `Type` = ' . DESTINATION_TYPE_COUNTRY;
+ WHERE `Type` = ' . DESTINATION_TYPE_COUNTRY;
+ $cache_value = $this->Conn->GetCol($sql, 'ShortIsoCode');
+ $this->Application->setCache($cache_key, $cache_value);
}
- return $this->Conn->GetOne($sql);
+ return $from_short ? $cache_value[$iso_code] : array_search($iso_code, $cache_value);
}
+
}
Event Timeline
Log In to Comment