Index: lib/moodlelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v retrieving revision 1.1492 diff -u -r1.1492 moodlelib.php --- lib/moodlelib.php 1 Nov 2010 12:20:39 -0000 1.1492 +++ lib/moodlelib.php 2 Nov 2010 11:22:01 -0000 @@ -9237,7 +9237,7 @@ * @return array */ function get_performance_info() { - global $CFG, $PERF, $DB; + global $CFG, $PERF, $DB, $PAGE; $info = array(); $info['html'] = ''; // holds userfriendly HTML representation @@ -9287,6 +9287,33 @@ } } + $jsmodules = $PAGE->requires->get_included_modules(); + if ($jsmodules) { + $yuicount = 0; + $othercount = 0; + $details = ''; + foreach ($jsmodules as $module => $backtraces) { + if (strpos($module, 'yui') === 0) { + $yuicount += 1; + } else { + $othercount += 1; + } + $details .= "

$module

"; + foreach ($backtraces as $backtrace) { + $details .= format_backtrace($backtrace); + } + } + + $info['html'] .= "Included YUI modules: $yuicount "; + $info['txt'] .= "includedyuimodules: $yuicount "; + $info['html'] .= "Other JavaScript modules: $othercount "; + $info['txt'] .= "includedjsmodules: $othercount "; + // Slightly odd to output the details in a display: none div. The point + // Is that it takes a lot of space, and if you care you can reveal it + // using firebug. + $info['html'] .= ""; + } + if (!empty($PERF->logwrites)) { $info['logwrites'] = $PERF->logwrites; $info['html'] .= 'Log DB writes '.$info['logwrites'].' '; Index: lib/outputrequirementslib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/outputrequirementslib.php,v retrieving revision 1.55 diff -u -r1.55 outputrequirementslib.php --- lib/outputrequirementslib.php 1 Nov 2010 17:45:00 -0000 1.55 +++ lib/outputrequirementslib.php 2 Nov 2010 11:22:01 -0000 @@ -477,6 +477,21 @@ } /** + * This is only used by the commented-out code below. + * @param string|array $module name of module, or full module specification. + * @return boolean whether this module has already been required. + */ + protected function is_already_included($module) { + if (is_string($module)) { + $modulename = $module; + } else { + $modulename = $module['name']; + } + return array_key_exists($modulename, $this->M_yui_loader->modules) || + array_key_exists($modulename, $this->extramodules); + } + + /** * Append YUI3 module to default YUI3 JS loader. * The structure of module array is described at http://developer.yahoo.com/yui/3/yui/: * @param string|array $module name of module (details are autodetected), or full module specification as array @@ -489,6 +504,28 @@ throw new coding_exception('Missing YUI3 module name or full description.'); } + /* + // Comment to anyone who reviews this: I think this is a small + // performance win, but I don't know if it would have undesirable + // side-effects. + if ($this->is_already_included($module)) { + if (debugging('', DEBUG_DEVELOPER)) { + if (is_string($module)) { + $modulename = $module; + } else { + $modulename = $module['name']; + } + if (array_key_exists($modulename, $this->M_yui_loader->modules)) { + $this->M_yui_loader->modules[$modulename]['requiredfrom'][] = debug_backtrace(); + } else { + $this->extramodules[$modulename]['requiredfrom'][] = debug_backtrace(); + } + } + + return; + } + */ + if (is_string($module)) { $module = $this->find_module($module); } @@ -509,11 +546,48 @@ } unset($module['strings']); + if (debugging('', DEBUG_DEVELOPER)) { + $module['requiredfrom'][] = debug_backtrace(); + } + if ($this->headdone) { $this->extramodules[$module['name']] = $module; } else { $this->M_yui_loader->modules[$module['name']] = $module; } + + /* + // Note to reviewers: This seems to be necessary, but again, I don't + // really understand it. + if (!empty($module['requires'])) { + foreach ($module['requires'] as $requirement) { + $this->js_module($requirement); + } + } + */ + } + + /** + * @return array of the js_modules that were included, and the stack traces + * of where they were included from. + */ + public function get_included_modules() { + $modules = array(); + foreach ($this->M_yui_loader->modules as $name => $module) { + $modules[$name] = array(); + if (!empty($module['requiredfrom'])) { + $modules[$name] += $module['requiredfrom']; + } + } + + foreach ($this->extramodules as $name => $module) { + $modules[$name] += array(); + if (!empty($module['requiredfrom'])) { + $modules[$name] += $module['requiredfrom']; + } + } + + return $modules; } /**