From dd5690916b8acb952669914c0e7dfc3ebf0842c2 Mon Sep 17 00:00:00 2001 From: cash Date: Wed, 25 Jan 2012 19:19:27 -0500 Subject: caching language data --- engine/lib/cache.php | 6 ++++++ engine/lib/configuration.php | 2 ++ engine/lib/elgglib.php | 7 ++++--- engine/lib/languages.php | 26 +++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 4 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/cache.php b/engine/lib/cache.php index 633c470eb..c7e0ae31c 100644 --- a/engine/lib/cache.php +++ b/engine/lib/cache.php @@ -455,6 +455,12 @@ function _elgg_cache_init() { elgg_save_system_cache($type, serialize($CONFIG->$var_name)); } } + + if ($CONFIG->system_cache_enabled && !$CONFIG->i18n_loaded_from_cache) { + foreach ($CONFIG->translations as $lang => $map) { + elgg_save_system_cache("$lang.php", serialize($map)); + } + } } elgg_register_event_handler('ready', 'system', '_elgg_cache_init'); diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php index 7f787331f..998cd1943 100644 --- a/engine/lib/configuration.php +++ b/engine/lib/configuration.php @@ -614,6 +614,8 @@ function _elgg_load_application_config() { $lastcached = datalist_get("simplecache_lastcached_$viewtype"); $CONFIG->lastcache = $lastcached; + $CONFIG->i18n_loaded_from_cache = false; + // this must be synced with the enum for the entities table $CONFIG->entity_types = array('group', 'object', 'site', 'user'); } diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index aba84bd48..11bdc7285 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -2062,7 +2062,8 @@ function elgg_walled_garden() { * 2. connects to database * 3. verifies the installation suceeded * 4. loads application configuration - * 5. loads site configuration + * 5. loads i18n data + * 6. loads site configuration * * @access private */ @@ -2071,14 +2072,14 @@ function _elgg_engine_boot() { set_error_handler('_elgg_php_error_handler'); set_exception_handler('_elgg_php_exception_handler'); - register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/"); - setup_db_connections(); verify_installation(); _elgg_load_application_config(); + register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/"); + _elgg_load_site_config(); _elgg_load_cache(); diff --git a/engine/lib/languages.php b/engine/lib/languages.php index 80c789ced..4dc094109 100644 --- a/engine/lib/languages.php +++ b/engine/lib/languages.php @@ -155,7 +155,6 @@ function register_translations($path, $load_all = false) { // Get the current language based on site defaults and user preference $current_language = get_current_language(); - elgg_log("Translations loaded from: $path"); // only load these files unless $load_all is true. $load_language_files = array( @@ -165,6 +164,29 @@ function register_translations($path, $load_all = false) { $load_language_files = array_unique($load_language_files); + if ($CONFIG->system_cache_enabled && !$load_all) { + // load language files from cache + $data = array(); + $loaded = true; + foreach ($load_language_files as $lang_file) { + $lang = substr($lang_file, 0, strpos($lang_file, '.')); + $data[$lang] = elgg_load_system_cache($lang_file); + if (!$data[$lang]) { + $loaded = false; + break; + } + } + + if ($loaded) { + foreach ($data as $lang => $map) { + add_translation($lang, unserialize($map)); + } + + $CONFIG->i18n_loaded_from_cache = true; + return true; + } + } + $handle = opendir($path); if (!$handle) { elgg_log("Could not open language path: $path", 'ERROR'); @@ -186,6 +208,8 @@ function register_translations($path, $load_all = false) { } } + elgg_log("Translations loaded from: $path"); + return $return; } -- cgit v1.2.3 From 62a356615c690e4020ef143332270ee57525b2c4 Mon Sep 17 00:00:00 2001 From: cash Date: Wed, 25 Jan 2012 19:31:01 -0500 Subject: plugins use language cache and cache is cleared properly --- engine/lib/cache.php | 10 ++-------- engine/lib/plugins.php | 3 +++ 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/cache.php b/engine/lib/cache.php index c7e0ae31c..b329c58ec 100644 --- a/engine/lib/cache.php +++ b/engine/lib/cache.php @@ -35,17 +35,11 @@ function elgg_get_system_cache() { /** * Reset the system cache by deleting the caches * - * @return bool + * @return void */ function elgg_reset_system_cache() { $cache = elgg_get_system_cache(); - - $result = true; - $cache_types = array('view_paths', 'view_types'); - foreach ($cache_types as $type) { - $result = $result && $cache->delete($type); - } - return $result; + $cache->clear(); } /** diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 07b21d276..488387ba7 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -303,6 +303,9 @@ function elgg_load_plugins() { if (elgg_get_config('system_cache_loaded')) { $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_VIEWS; + if ($CONFIG->i18n_loaded_from_cache) { + $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_LANGUAGES; + } } $return = true; -- cgit v1.2.3 From df535f87fbf6641bcadc2ffaa01846cad4cd9524 Mon Sep 17 00:00:00 2001 From: cash Date: Wed, 25 Jan 2012 20:19:33 -0500 Subject: not loading language files a second time when session initialized --- engine/lib/languages.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/languages.php b/engine/lib/languages.php index 4dc094109..c6e2fc152 100644 --- a/engine/lib/languages.php +++ b/engine/lib/languages.php @@ -167,23 +167,33 @@ function register_translations($path, $load_all = false) { if ($CONFIG->system_cache_enabled && !$load_all) { // load language files from cache $data = array(); - $loaded = true; + $anything_loaded = false; + $missing_cache = false; foreach ($load_language_files as $lang_file) { $lang = substr($lang_file, 0, strpos($lang_file, '.')); - $data[$lang] = elgg_load_system_cache($lang_file); - if (!$data[$lang]) { - $loaded = false; - break; + // only load if this language isn't already loaded + if (!isset($CONFIG->translations) || !isset($CONFIG->translations[$lang])) { + $data[$lang] = elgg_load_system_cache($lang_file); + if (!$data[$lang]) { + $missing_cache = true; + break; + } else { + $anything_loaded = true; + } } } - if ($loaded) { + // did we load all requested languages from the cache + if (!$missing_cache && $anything_loaded) { foreach ($data as $lang => $map) { add_translation($lang, unserialize($map)); } $CONFIG->i18n_loaded_from_cache = true; return true; + } else if (!$missing_cache && !$anything_loaded) { + // everything previously loaded from cache + return true; } } -- cgit v1.2.3 From 06ba6ccfb8bb5a8da8464d8f86454b468744c9cc Mon Sep 17 00:00:00 2001 From: cash Date: Wed, 1 Feb 2012 18:57:00 -0500 Subject: fixed logic that caused plugin language files to not be loaded --- engine/lib/languages.php | 35 +++++++++++++++++++---------------- engine/lib/plugins.php | 3 --- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/languages.php b/engine/lib/languages.php index c6e2fc152..bf6829a39 100644 --- a/engine/lib/languages.php +++ b/engine/lib/languages.php @@ -145,9 +145,16 @@ function elgg_echo($message_key, $args = array(), $language = "") { function register_translations($path, $load_all = false) { global $CONFIG; + static $load_from_cache; + static $cache_loaded_langs; + if (!isset($load_from_cache)) { + $load_from_cache = $CONFIG->system_cache_enabled; + $cache_loaded_langs = array(); + } + $path = sanitise_filepath($path); - // Make a note of this path just incase we need to register this language later + // Make a note of this path just in case we need to register this language later if (!isset($CONFIG->language_paths)) { $CONFIG->language_paths = array(); } @@ -164,36 +171,29 @@ function register_translations($path, $load_all = false) { $load_language_files = array_unique($load_language_files); - if ($CONFIG->system_cache_enabled && !$load_all) { + if ($load_from_cache && !$load_all) { // load language files from cache $data = array(); - $anything_loaded = false; - $missing_cache = false; foreach ($load_language_files as $lang_file) { $lang = substr($lang_file, 0, strpos($lang_file, '.')); - // only load if this language isn't already loaded - if (!isset($CONFIG->translations) || !isset($CONFIG->translations[$lang])) { + if (!isset($cache_loaded_langs[$lang])) { $data[$lang] = elgg_load_system_cache($lang_file); - if (!$data[$lang]) { - $missing_cache = true; - break; + if ($data[$lang]) { + $cache_loaded_langs[$lang] = true; } else { - $anything_loaded = true; + // this language file not cached yet + $load_from_cache = false; } } } - // did we load all requested languages from the cache - if (!$missing_cache && $anything_loaded) { + // are we still suppose to load from cache + if ($load_from_cache) { foreach ($data as $lang => $map) { add_translation($lang, unserialize($map)); } - $CONFIG->i18n_loaded_from_cache = true; return true; - } else if (!$missing_cache && !$anything_loaded) { - // everything previously loaded from cache - return true; } } @@ -220,6 +220,9 @@ function register_translations($path, $load_all = false) { elgg_log("Translations loaded from: $path"); + // make sure caching code saves language data if system cache is on + $CONFIG->i18n_loaded_from_cache = false; + return $return; } diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 488387ba7..07b21d276 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -303,9 +303,6 @@ function elgg_load_plugins() { if (elgg_get_config('system_cache_loaded')) { $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_VIEWS; - if ($CONFIG->i18n_loaded_from_cache) { - $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_LANGUAGES; - } } $return = true; -- cgit v1.2.3