Commit bca66646 authored by Dries's avatar Dries

- Performance improvement. Patch by Zbynek.

  1) Even when string is not translated, put it in the cache and save a
     query for each untranslated string.
  2) When there is no cache, create one.
parent c09ab23b
...@@ -89,7 +89,12 @@ function locale_refresh_cache() { ...@@ -89,7 +89,12 @@ function locale_refresh_cache() {
foreach (array_keys($languages) as $locale) { foreach (array_keys($languages) as $locale) {
$result = db_query("SELECT string, %s FROM locales", $locale); $result = db_query("SELECT string, %s FROM locales", $locale);
while ($data = db_fetch_object($result)) { while ($data = db_fetch_object($result)) {
$t[$data->string] = $data->$locale; if (empty($data->$locale)) {
$t[$data->string] = $data->string;
}
else {
$t[$data->string] = $data->$locale;
}
} }
cache_set("locale:$locale", serialize($t)); cache_set("locale:$locale", serialize($t));
} }
...@@ -266,9 +271,11 @@ function locale($string) { ...@@ -266,9 +271,11 @@ function locale($string) {
if (!isset($locale_t)) { if (!isset($locale_t)) {
$cache = cache_get("locale:$locale"); $cache = cache_get("locale:$locale");
if ($cache) { if ($cache == 0) {
$locale_t = unserialize($cache->data); locale_refresh_cache();
$cache = cache_get("locale:$locale");
} }
$locale_t = unserialize($cache->data);
} }
if ($locale_t[$string] != "") { if ($locale_t[$string] != "") {
...@@ -278,6 +285,7 @@ function locale($string) { ...@@ -278,6 +285,7 @@ function locale($string) {
$result = db_query("SELECT lid, $locale FROM locales WHERE string = '%s'", $string); $result = db_query("SELECT lid, $locale FROM locales WHERE string = '%s'", $string);
if (!db_fetch_object($result)) { if (!db_fetch_object($result)) {
db_query("INSERT INTO locales (string, location) VALUES ('%s', '%s')", $string, request_uri()); db_query("INSERT INTO locales (string, location) VALUES ('%s', '%s')", $string, request_uri());
cache_clear_all("locale:$locale");
} }
} }
......
...@@ -89,7 +89,12 @@ function locale_refresh_cache() { ...@@ -89,7 +89,12 @@ function locale_refresh_cache() {
foreach (array_keys($languages) as $locale) { foreach (array_keys($languages) as $locale) {
$result = db_query("SELECT string, %s FROM locales", $locale); $result = db_query("SELECT string, %s FROM locales", $locale);
while ($data = db_fetch_object($result)) { while ($data = db_fetch_object($result)) {
$t[$data->string] = $data->$locale; if (empty($data->$locale)) {
$t[$data->string] = $data->string;
}
else {
$t[$data->string] = $data->$locale;
}
} }
cache_set("locale:$locale", serialize($t)); cache_set("locale:$locale", serialize($t));
} }
...@@ -266,9 +271,11 @@ function locale($string) { ...@@ -266,9 +271,11 @@ function locale($string) {
if (!isset($locale_t)) { if (!isset($locale_t)) {
$cache = cache_get("locale:$locale"); $cache = cache_get("locale:$locale");
if ($cache) { if ($cache == 0) {
$locale_t = unserialize($cache->data); locale_refresh_cache();
$cache = cache_get("locale:$locale");
} }
$locale_t = unserialize($cache->data);
} }
if ($locale_t[$string] != "") { if ($locale_t[$string] != "") {
...@@ -278,6 +285,7 @@ function locale($string) { ...@@ -278,6 +285,7 @@ function locale($string) {
$result = db_query("SELECT lid, $locale FROM locales WHERE string = '%s'", $string); $result = db_query("SELECT lid, $locale FROM locales WHERE string = '%s'", $string);
if (!db_fetch_object($result)) { if (!db_fetch_object($result)) {
db_query("INSERT INTO locales (string, location) VALUES ('%s', '%s')", $string, request_uri()); 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