Skip to content

Commit

Permalink
Merged from MOODLE_14_STABLE. Added option to cache langlist in datar…
Browse files Browse the repository at this point in the history
…oot/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.
  • Loading branch information
martinlanghoff committed Apr 11, 2005
1 parent e170f66 commit 6e6053b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions admin/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
}
flush();

if (!empty($CFG->langcache)) {
get_list_of_languages();
}
flush();

if (!empty($CFG->notifyloginfailures)) {
notify_login_failures();
}
Expand Down
23 changes: 23 additions & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 6e6053b

Please sign in to comment.