Browse files

Added option to cache langlist in dataroot/cache/languages. If enable…

…d saves around 10MB of memory and 40 includes (some really large)
  • Loading branch information...
1 parent 7940571 commit d162ab230795ec58200ba7a1db841112d23641e2 martinlanghoff committed Apr 11, 2005
Showing with 37 additions and 0 deletions.
  1. +5 −0 admin/cron.php
  2. +9 −0 config-dist.php
  3. +23 −0 lib/moodlelib.php
View
5 admin/cron.php
@@ -118,6 +118,11 @@
}
flush();
+ if (!empty($CFG->langcache)) {
+ get_list_of_languages();
+ }
+ flush();
+
if (!empty($CFG->notifyloginfailures)) {
notify_login_failures();
}
View
9 config-dist.php
@@ -182,6 +182,15 @@
// settings. Use this if you want to control session configuration
// from php.ini, httpd.conf or .htaccess files.
// $CFG->respectsessionsettings = true;
+//
+// Generating the language menu consumes a *lot* of memory and queries a
+// lot of files. if you are looking for performance, and not adding/removing
+// languages often, enable the language menu cache. With the cache enabled,
+// Moodle only refreshes the list of languages every few invocations of the
+// cron script. For maximum efficiency, make sure your cron is called from the
+// commandline, not via HTTP.
+// $CFG->langcache = true;
+//
//=========================================================================
// ALL DONE! To continue installation, visit your main page with a browser
View
23 lib/moodlelib.php
@@ -2413,6 +2413,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) {
@@ -2432,6 +2446,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;
}

0 comments on commit d162ab2

Please sign in to comment.