Commit b3e42eb5 authored by Dries's avatar Dries
Browse files

- Patch #626688 by justinrandell, catch, chx: add caching for system_list().

parent 1b307cc7
...@@ -600,6 +600,7 @@ function _drupal_install_module($module) { ...@@ -600,6 +600,7 @@ function _drupal_install_module($module) {
module_invoke($module, 'install'); module_invoke($module, 'install');
$versions = drupal_get_schema_versions($module); $versions = drupal_get_schema_versions($module);
drupal_set_installed_schema_version($module, $versions ? max($versions) : SCHEMA_INSTALLED); drupal_set_installed_schema_version($module, $versions ? max($versions) : SCHEMA_INSTALLED);
system_list_reset();
return TRUE; return TRUE;
} }
} }
......
...@@ -115,9 +115,10 @@ function system_list($type) { ...@@ -115,9 +115,10 @@ function system_list($type) {
$bootstrap_list = db_query("SELECT name, filename FROM {system} WHERE status = 1 AND bootstrap = 1 AND type = 'module' ORDER BY weight ASC, name ASC")->fetchAllAssoc('name'); $bootstrap_list = db_query("SELECT name, filename FROM {system} WHERE status = 1 AND bootstrap = 1 AND type = 'module' ORDER BY weight ASC, name ASC")->fetchAllAssoc('name');
cache_set('bootstrap_modules', $bootstrap_list, 'cache_bootstrap'); cache_set('bootstrap_modules', $bootstrap_list, 'cache_bootstrap');
} }
// To avoid a separate database lookup for the filepath, prime the
// drupal_get_filename() static cache for bootstrap modules only.
// The rest is stored separately to keep the bootstrap module cache small.
foreach ($bootstrap_list as $module) { foreach ($bootstrap_list as $module) {
// Prime the drupal_get_filename() static cache to avoid subsequent
// queries to retrieve module filename.
drupal_get_filename('module', $module->name, $module->filename); drupal_get_filename('module', $module->name, $module->filename);
} }
// We only return the module names here since module_list() doesn't need // We only return the module names here since module_list() doesn't need
...@@ -125,33 +126,42 @@ function system_list($type) { ...@@ -125,33 +126,42 @@ function system_list($type) {
$lists['bootstrap'] = array_keys($bootstrap_list); $lists['bootstrap'] = array_keys($bootstrap_list);
} }
// Otherwise build the list for enabled modules and themes. // Otherwise build the list for enabled modules and themes.
elseif (!isset($lists)) { elseif (!isset($lists['module_enable'])) {
$lists = array( if ($cached = cache_get('system_list', 'cache_bootstrap')) {
'module_enabled' => array(), $lists = $cached->data;
'theme' => array(), }
); else {
// The module name (rather than the filename) is used as the fallback $lists = array(
// weighting in order to guarantee consistent behavior across different 'module_enabled' => array(),
// Drupal installations, which might have modules installed in different 'theme' => array(),
// locations in the file system. The ordering here must also be 'filepaths' => array(),
// consistent with the one used in module_implements(). );
$result = db_query("SELECT * FROM {system} ORDER BY weight ASC, name ASC"); // The module name (rather than the filename) is used as the fallback
foreach ($result as $record) { // weighting in order to guarantee consistent behavior across different
if ($record->type == 'module' && $record->status) { // Drupal installations, which might have modules installed in different
// Build a list of all enabled modules. // locations in the file system. The ordering here must also be
$lists['module_enabled'][$record->name] = $record->name; // consistent with the one used in module_implements().
} $result = db_query("SELECT * FROM {system} ORDER BY weight ASC, name ASC");
// Build a list of themes. foreach ($result as $record) {
if ($record->type == 'theme') { if ($record->type == 'module' && $record->status) {
$lists['theme'][$record->name] = $record; // Build a list of all enabled modules.
} $lists['module_enabled'][$record->name] = $record->name;
}
// Additionally prime drupal_get_filename() with the filename and type // Build a list of themes.
// for each record, this prevents subsequent database lookups when if ($record->type == 'theme') {
// drupal_get_filename() is called without the 'file' argument. $lists['theme'][$record->name] = $record;
if ($record->status) { }
drupal_get_filename($record->type, $record->name, $record->filename); // Build a list of filenames so drupal_get_filename can use it.
if ($record->status) {
$lists['filepaths'][] = array('type' => $record->type, 'name' => $record->name, 'filepath' => $record->filename);
}
} }
cache_set('system_list', $lists, 'cache_bootstrap');
}
// To avoid a separate database lookup for the filepath, prime the
// drupal_get_filename() static cache with all enabled modules and themes.
foreach ($lists['filepaths'] as $item) {
drupal_get_filename($item['type'], $item['name'], $item['filepath']);
} }
} }
...@@ -164,6 +174,7 @@ function system_list($type) { ...@@ -164,6 +174,7 @@ function system_list($type) {
function system_list_reset() { function system_list_reset() {
drupal_static_reset('system_list'); drupal_static_reset('system_list');
cache_clear_all('bootstrap_modules', 'cache_bootstrap'); cache_clear_all('bootstrap_modules', 'cache_bootstrap');
cache_clear_all('system_list', 'cache_bootstrap');
} }
/** /**
......
...@@ -562,7 +562,7 @@ function list_themes($refresh = FALSE) { ...@@ -562,7 +562,7 @@ function list_themes($refresh = FALSE) {
if ($refresh) { if ($refresh) {
$list = array(); $list = array();
drupal_static_reset('system_list'); system_list_reset();
} }
if (empty($list)) { if (empty($list)) {
......
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