Commit fdeb890b authored by Dries's avatar Dries
Browse files

- Patch #521838 by catch, jrchamp, CorniI, sun | Damien Tournoud, drewish,...

- Patch #521838 by catch, jrchamp, CorniI, sun | Damien Tournoud, drewish, chx, moshe weitzman, yched, Dries: drupal_get_schema_versions() took 30% of page execution time on /admin.
parent 0622dfe9
...@@ -92,24 +92,34 @@ function drupal_load_updates() { ...@@ -92,24 +92,34 @@ function drupal_load_updates() {
* Otherwise, FALSE. * Otherwise, FALSE.
*/ */
function drupal_get_schema_versions($module) { function drupal_get_schema_versions($module) {
$updates = array(); $updates = &drupal_static(__FUNCTION__, NULL);
$functions = get_defined_functions(); if (!isset($updates)) {
foreach ($functions['user'] as $function) { $updates = array();
if (strpos($function, $module . '_update_') === 0) { // Prepare regular expression to match all possible defined hook_update_N().
$version = substr($function, strlen($module . '_update_')); $modules = db_query("SELECT name FROM {system} WHERE type = 'module'")
if (is_numeric($version)) { ->fetchCol();
$updates[] = $version; $regexp = '/^(?P<module>' . implode('|', $modules) . ')_update_(?P<version>\d+)$/';
$functions = get_defined_functions();
// Narrow this down to functions ending with an integer, since all
// hook_update_N() functions end this way, and there are other
// possible functions which match '_update_'. We use preg_grep() here
// instead of foreaching through all defined functions, since the loop
// through all PHP functions can take significant page execution time
// and this function is called on every administrative page via
// system_requirements().
foreach (preg_grep('/_\d+$/', $functions['user']) as $function) {
// If this function is a module update function, add it to the list of
// module updates.
if (preg_match($regexp, $function, $matches)) {
$updates[$matches['module']][] = $matches['version'];
} }
} }
// Ensure that updates are applied in numerical order.
foreach ($updates as &$module_updates) {
sort($module_updates, SORT_NUMERIC);
}
} }
if (count($updates) == 0) { return isset($updates[$module]) ? $updates[$module] : FALSE;
return FALSE;
}
// Make sure updates are run in numeric order, not in definition order.
sort($updates, SORT_NUMERIC);
return $updates;
} }
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment