Commit 7e67d991 authored by Dries's avatar Dries

- Locale module improvements: better performance, reduce memory footprint.
  Patch by Bart.
parent 9eba2ac7
......@@ -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");
}
......
......@@ -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");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment