mirror of
https://github.com/moodle/moodle.git
synced 2025-06-02 14:15:11 +02:00
Merged from MOODLE_14_STABLE. Added option to cache langlist in dataroot/cache/languages. If enabled saves around 10MB of memory and 40 includes (some really large). In HEAD we also get a nice option select in admin->variables.
This commit is contained in:
parent
e170f66546
commit
6e6053bd18
@ -118,6 +118,11 @@
|
||||
}
|
||||
flush();
|
||||
|
||||
if (!empty($CFG->langcache)) {
|
||||
get_list_of_languages();
|
||||
}
|
||||
flush();
|
||||
|
||||
if (!empty($CFG->notifyloginfailures)) {
|
||||
notify_login_failures();
|
||||
}
|
||||
|
@ -4161,6 +4161,20 @@ function get_list_of_languages() {
|
||||
|
||||
$languages = array();
|
||||
|
||||
if ( (!defined('FULLME') || FULLME !== 'cron')
|
||||
&& !empty($CFG->langcache) && file_exists($CFG->dataroot .'/cache/languages')) {
|
||||
// read from cache
|
||||
$lines = file($CFG->dataroot .'/cache/languages');
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if (preg_match('/^(\w+)\s+(.+)/', $line, $matches)) {
|
||||
$languages[$matches[1]] = $matches[2];
|
||||
}
|
||||
}
|
||||
unset($lines); unset($line); unset($matches);
|
||||
return $languages;
|
||||
}
|
||||
|
||||
if (!empty($CFG->langlist)) { // use admin's list of languages
|
||||
$langlist = explode(',', $CFG->langlist);
|
||||
foreach ($langlist as $lang) {
|
||||
@ -4180,6 +4194,15 @@ function get_list_of_languages() {
|
||||
unset($string);
|
||||
}
|
||||
}
|
||||
if ( defined('FULLME') && FULLME === 'cron' && !empty($CFG->langcache)) {
|
||||
if ($file = fopen($CFG->dataroot .'/cache/languages', 'w')) {
|
||||
foreach ($languages as $key => $value) {
|
||||
fwrite($file, "$key $value\n");
|
||||
}
|
||||
fclose($file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $languages;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user