diff options
author | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-10-15 19:51:06 +0000 |
---|---|---|
committer | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-10-15 19:51:06 +0000 |
commit | 3a8f208b7a59427f409691c09f94343c7a3c45a5 (patch) | |
tree | b7267e41333c973ef6894a44b2f17965ab04282d /modules/locale | |
parent | 59150295800f9a918c26da25855e41dba78eb5b8 (diff) | |
download | brdo-3a8f208b7a59427f409691c09f94343c7a3c45a5.tar.gz brdo-3a8f208b7a59427f409691c09f94343c7a3c45a5.tar.bz2 |
#183056 by JirkaRybka: improve locale cache handling performance
- always prune the whole cache as string additions affect all languages
- rebuild the language caches as needed, distributing this load among page requests
Diffstat (limited to 'modules/locale')
-rw-r--r-- | modules/locale/locale.module | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/modules/locale/locale.module b/modules/locale/locale.module index 1d6d5c83d..a7e477398 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -321,13 +321,19 @@ function locale($string = NULL, $langcode = NULL) { // perspective that is a really bad idea, so we have no user // interface for this. Be careful when turning this option off! if (variable_get('locale_cache_strings', 1) == 1) { - if (!($cache = cache_get('locale:'. $langcode, 'cache'))) { - locale_refresh_cache(); - $cache = cache_get('locale:'. $langcode, 'cache'); - } - if ($cache) { + if ($cache = cache_get('locale:'. $langcode, 'cache')) { $locale_t[$langcode] = $cache->data; } + else { + // Refresh database stored cache of translations for given language. + // We only store short strings used in current version, to improve + // performance and consume less memory. + $result = db_query("SELECT s.source, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.textgroup = 'default' AND s.version = '%s' AND LENGTH(s.source) < 75", $langcode, VERSION); + while ($data = db_fetch_object($result)) { + $locale_t[$langcode][$data->source] = (empty($data->translation) ? TRUE : $data->translation); + } + cache_set('locale:'. $langcode, $locale_t[$langcode]); + } } } @@ -346,7 +352,7 @@ function locale($string = NULL, $langcode = NULL) { // and clear cache, to include the string into caching next time. Saved version is // also a string-history information for later pruning of the tables. db_query("UPDATE {locales_source} SET version = '%s' WHERE lid = %d LIMIT 1", VERSION, $translation->lid); - cache_clear_all('locale:'. $langcode, 'cache'); + cache_clear_all('locale:', 'cache', TRUE); } } else { @@ -354,7 +360,7 @@ function locale($string = NULL, $langcode = NULL) { db_query("INSERT INTO {locales_source} (location, source, textgroup, version) VALUES ('%s', '%s', 'default', '%s')", request_uri(), $string, VERSION); $locale_t[$langcode][$string] = TRUE; // Clear locale cache so this string can be added in a later request. - cache_clear_all('locale:'. $langcode, 'cache'); + cache_clear_all('locale:', 'cache', TRUE); } } @@ -362,26 +368,6 @@ function locale($string = NULL, $langcode = NULL) { } /** - * Refreshes database stored cache of translations. - * - * We only store short strings used in current version, to improve performance and consume less memory. - */ -function locale_refresh_cache() { - $languages = language_list('enabled'); - $languages = $languages['1']; - unset($languages['en']); - - foreach ($languages as $language) { - $result = db_query("SELECT s.source, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.textgroup = 'default' AND s.version = '%s' AND LENGTH(s.source) < 75", $language->language, VERSION); - $t = array(); - while ($data = db_fetch_object($result)) { - $t[$data->source] = (empty($data->translation) ? TRUE : $data->translation); - } - cache_set('locale:'. $language->language, $t); - } -} - -/** * Returns plural form index for a specific number. * * The index is computed from the formula of this language. |