summaryrefslogtreecommitdiff
path: root/modules/locale
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-09-02 15:19:16 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-09-02 15:19:16 +0000
commitb5331d08591afbb2b46e709cc424591a9c093466 (patch)
tree8655c5d0faddb402bb60cb6bae8443a88849260e /modules/locale
parente310d9e4a4b7bd94e5e743f8dbf3ebdd530ced1e (diff)
downloadbrdo-b5331d08591afbb2b46e709cc424591a9c093466.tar.gz
brdo-b5331d08591afbb2b46e709cc424591a9c093466.tar.bz2
#171646 by JirkaRybka: store version usage information for every source string, optimize caching and prune the initially unused strings
Diffstat (limited to 'modules/locale')
-rw-r--r--modules/locale/locale.install9
-rw-r--r--modules/locale/locale.module16
-rw-r--r--modules/locale/locale.schema2
3 files changed, 23 insertions, 4 deletions
diff --git a/modules/locale/locale.install b/modules/locale/locale.install
index b532fecfa..f283dca1c 100644
--- a/modules/locale/locale.install
+++ b/modules/locale/locale.install
@@ -106,6 +106,15 @@ function locale_update_6004() {
}
/**
+ * Prune strings with no translations (will be automatically re-registered if still in use)
+ */
+function locale_update_6005() {
+ $ret = array();
+ $ret[] = update_sql("DELETE s FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE t.lid IS NULL");
+ return $ret;
+}
+
+/**
* @} End of "defgroup updates-5.x-to-6.x"
*/
diff --git a/modules/locale/locale.module b/modules/locale/locale.module
index a9eb60014..28ff60ff2 100644
--- a/modules/locale/locale.module
+++ b/modules/locale/locale.module
@@ -335,15 +335,23 @@ function locale($string = NULL, $langcode = NULL) {
if (!isset($locale_t[$langcode][$string])) {
// We do not have this translation cached, so get it from the DB.
- $translation = db_fetch_object(db_query("SELECT s.lid, t.translation FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.source = '%s' AND s.textgroup = 'default'", $langcode, $string));
+ $translation = db_fetch_object(db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.source = '%s' AND s.textgroup = 'default'", $langcode, $string));
if ($translation) {
// We have the source string at least.
// Cache translation string or TRUE if no translation exists.
$locale_t[$langcode][$string] = (empty($translation->translation) ? TRUE : $translation->translation);
+
+ if ($translation->version != VERSION) {
+ // This is the first use of this string under current Drupal version. Save version
+ // 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');
+ }
}
else {
// We don't have the source string, cache this as untranslated.
- db_query("INSERT INTO {locales_source} (location, source, textgroup) VALUES ('%s', '%s', 'default')", request_uri(), $string);
+ 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');
@@ -356,7 +364,7 @@ function locale($string = NULL, $langcode = NULL) {
/**
* Refreshes database stored cache of translations.
*
- * We only store short strings to improve performance and consume less memory.
+ * We only store short strings used in current version, to improve performance and consume less memory.
*/
function locale_refresh_cache() {
$languages = language_list('enabled');
@@ -364,7 +372,7 @@ function locale_refresh_cache() {
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 LENGTH(s.source) < 75", $language->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);
diff --git a/modules/locale/locale.schema b/modules/locale/locale.schema
index f511a020f..be31341e9 100644
--- a/modules/locale/locale.schema
+++ b/modules/locale/locale.schema
@@ -40,6 +40,8 @@ function locale_schema() {
'textgroup' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'default'),
// The original string in English.
'source' => array('type' => 'text', 'mysql_type' => 'blob', 'not null' => TRUE),
+ // Drupal core version, which last used the string.
+ 'version' => array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => 'none'),
),
'primary key' => array('lid'),
'indexes' => array