MDL-65327 performance: Lazy-load module name strings

This commit is contained in:
Mark Johnson 2019-04-10 16:27:36 +01:00
parent 6735197cc2
commit d91aa1e760
4 changed files with 10 additions and 11 deletions

View file

@ -261,8 +261,8 @@ class core_course_external extends external_api {
$module['id'] = $cm->id;
$module['name'] = external_format_string($cm->name, $modcontext->id);
$module['instance'] = $cm->instance;
$module['modname'] = $cm->modname;
$module['modplural'] = $cm->modplural;
$module['modname'] = (string) $cm->modname;
$module['modplural'] = (string) $cm->modplural;
$module['modicon'] = $cm->get_icon_url()->out(false);
$module['indent'] = $cm->indent;
$module['onclick'] = $cm->onclick;

View file

@ -559,12 +559,10 @@ function get_module_types_names($plural = false) {
if ($allmods = $DB->get_records("modules")) {
foreach ($allmods as $mod) {
if (file_exists("$CFG->dirroot/mod/$mod->name/lib.php") && $mod->visible) {
$modnames[0][$mod->name] = get_string("modulename", "$mod->name");
$modnames[1][$mod->name] = get_string("modulenameplural", "$mod->name");
$modnames[0][$mod->name] = get_string("modulename", "$mod->name", null, true);
$modnames[1][$mod->name] = get_string("modulenameplural", "$mod->name", null, true);
}
}
core_collator::asort($modnames[0]);
core_collator::asort($modnames[1]);
}
}
return $modnames[(int)$plural];