diff options
-rw-r--r-- | modules/locale.module | 16 | ||||
-rw-r--r-- | modules/locale/locale.module | 16 |
2 files changed, 26 insertions, 6 deletions
diff --git a/modules/locale.module b/modules/locale.module index ed9e89244..6a4bc59eb 100644 --- a/modules/locale.module +++ b/modules/locale.module @@ -114,7 +114,11 @@ function locale_refresh_cache() { global $languages; foreach (array_keys($languages) as $locale) { - $result = db_query("SELECT string, %s FROM {locales} ", $locale); + /* + ** We only load short strings into the cache to improve both performance + ** and memory usages. + */ + $result = db_query("SELECT string, %s FROM {locales} WHERE LENGTH(string) < 75", $locale); while ($data = db_fetch_object($result)) { if (empty($data->$locale)) { $t[$data->string] = $data->string; @@ -344,12 +348,18 @@ function locale($string) { $locale_t = unserialize($cache->data); } - if (is_array($locale_t) && array_key_exists($string, $locale_t)) { + if (isset($locale_t[$string])) { $string = $locale_t[$string]; } else { $result = db_query("SELECT lid, $locale FROM {locales} WHERE string = '%s'", $string); - if (!db_fetch_object($result)) { + if ($trans = db_fetch_object($result)) { + if (!empty($trans->$locale)) { + $locale_t[$string] = $trans->$locale; + $string = $trans->$locale; + } + } + else { db_query("INSERT INTO {locales} (string, location) VALUES ('%s', '%s')", $string, request_uri()); cache_clear_all("locale:$locale"); } diff --git a/modules/locale/locale.module b/modules/locale/locale.module index ed9e89244..6a4bc59eb 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -114,7 +114,11 @@ function locale_refresh_cache() { global $languages; foreach (array_keys($languages) as $locale) { - $result = db_query("SELECT string, %s FROM {locales} ", $locale); + /* + ** We only load short strings into the cache to improve both performance + ** and memory usages. + */ + $result = db_query("SELECT string, %s FROM {locales} WHERE LENGTH(string) < 75", $locale); while ($data = db_fetch_object($result)) { if (empty($data->$locale)) { $t[$data->string] = $data->string; @@ -344,12 +348,18 @@ function locale($string) { $locale_t = unserialize($cache->data); } - if (is_array($locale_t) && array_key_exists($string, $locale_t)) { + if (isset($locale_t[$string])) { $string = $locale_t[$string]; } else { $result = db_query("SELECT lid, $locale FROM {locales} WHERE string = '%s'", $string); - if (!db_fetch_object($result)) { + if ($trans = db_fetch_object($result)) { + if (!empty($trans->$locale)) { + $locale_t[$string] = $trans->$locale; + $string = $trans->$locale; + } + } + else { db_query("INSERT INTO {locales} (string, location) VALUES ('%s', '%s')", $string, request_uri()); cache_clear_all("locale:$locale"); } |