diff options
author | Dries Buytaert <dries@buytaert.net> | 2003-12-28 09:40:49 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2003-12-28 09:40:49 +0000 |
commit | 7e67d99178b458a9c6537247dbf204e27305197f (patch) | |
tree | 97cd33af63b178817ed90106e55c7831fdb07595 /modules | |
parent | 9eba2ac77f9f0674f13cf6bfdecd7f1a13039019 (diff) | |
download | brdo-7e67d99178b458a9c6537247dbf204e27305197f.tar.gz brdo-7e67d99178b458a9c6537247dbf204e27305197f.tar.bz2 |
- Locale module improvements: better performance, reduce memory footprint.
Patch by Bart.
Diffstat (limited to 'modules')
-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"); } |