Commit 9d7070fd authored by Dries's avatar Dries

- Patch #577950 by marcingy: API-cleanup: Factor module_implements() ...

- Patch #577950 by marcingy: API-cleanup: Factor module_implements()  parameter into it's own function.
parent d23a4ab4
......@@ -418,7 +418,7 @@ function module_enable($module_list, $enable_dependencies = TRUE) {
// Refresh the module list to include it.
system_list_reset();
module_list(TRUE);
module_implements('', FALSE, TRUE);
module_implements_reset();
_system_update_bootstrap_status();
// Update the registry to include it.
registry_update();
......@@ -541,7 +541,7 @@ function module_disable($module_list, $disable_dependents = TRUE) {
// Refresh the module list to exclude the disabled modules.
system_list_reset();
module_list(TRUE);
module_implements('', FALSE, TRUE);
module_implements_reset();
// Invoke hook_modules_disabled before disabling modules,
// so we can still call module hooks to get information.
module_invoke_all('modules_disabled', $invoke_modules);
......@@ -621,17 +621,13 @@ function module_hook($module, $hook) {
* @param $sort
* By default, modules are ordered by weight and filename, settings this option
* to TRUE, module list will be ordered by module name.
* @param $reset
* For internal use only: Whether to force the stored list of hook
* implementations to be regenerated (such as after enabling a new module,
* before processing hook_enable).
*
* @return
* An array with the names of the modules which are implementing this hook.
*
* @see module_implements_write_cache()
*/
function module_implements($hook, $sort = FALSE, $reset = FALSE) {
function module_implements($hook, $sort = FALSE) {
// Use the advanced drupal_static() pattern, since this is called very often.
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
......@@ -639,25 +635,6 @@ function module_implements($hook, $sort = FALSE, $reset = FALSE) {
}
$implementations = &$drupal_static_fast['implementations'];
// We maintain a persistent cache of hook implementations in addition to the
// static cache to avoid looping through every module and every hook on each
// request. Benchmarks show that the benefit of this caching outweighs the
// additional database hit even when using the default database caching
// backend and only a small number of modules are enabled. The cost of the
// cache_get() is more or less constant and reduced further when non-database
// caching backends are used, so there will be more significant gains when a
// large number of modules are installed or hooks invoked, since this can
// quickly lead to module_hook() being called several thousand times
// per request.
if ($reset) {
$implementations = array();
cache('bootstrap')->set('module_implements', array());
drupal_static_reset('module_hook_info');
drupal_static_reset('drupal_alter');
cache('bootstrap')->delete('hook_info');
return;
}
// Fetch implementations from cache.
if (empty($implementations)) {
$implementations = cache('bootstrap')->get('module_implements');
......@@ -714,6 +691,27 @@ function module_implements($hook, $sort = FALSE, $reset = FALSE) {
return array_keys($implementations[$hook]);
}
/**
* Regenerate the stored list of hook implementations.
*/
function module_implements_reset() {
// We maintain a persistent cache of hook implementations in addition to the
// static cache to avoid looping through every module and every hook on each
// request. Benchmarks show that the benefit of this caching outweighs the
// additional database hit even when using the default database caching
// backend and only a small number of modules are enabled. The cost of the
// cache_get() is more or less constant and reduced further when non-database
// caching backends are used, so there will be more significant gains when a
// large number of modules are installed or hooks invoked, since this can
// quickly lead to module_hook() being called several thousand times
// per request.
drupal_static_reset('module_implements');
cache('bootstrap')->set('module_implements', array());
drupal_static_reset('module_hook_info');
drupal_static_reset('drupal_alter');
cache('bootstrap')->delete('hook_info');
}
/**
* Retrieve a list of what hooks are explicitly declared.
*/
......
......@@ -93,7 +93,7 @@ function _registry_update() {
$unchanged_resources[$key] = $file;
}
}
module_implements('', FALSE, TRUE);
module_implements_reset();
_registry_check_code(REGISTRY_RESET_LOOKUP_CACHE);
}
catch (Exception $e) {
......
......@@ -2475,7 +2475,7 @@ class LocaleLanguageNegotiationInfoFunctionalTest extends DrupalWebTestCase {
$function = "module_{$op}";
$function($modules);
// Reset hook implementation cache.
module_implements(NULL, FALSE, TRUE);
module_implements_reset();
}
drupal_static_reset('language_types_info');
......
......@@ -1485,7 +1485,7 @@ protected function tearDown() {
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements('', FALSE, TRUE);
module_implements_reset();
// Reset the Field API.
field_cache_clear();
......
......@@ -177,7 +177,7 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
module_list(TRUE);
module_implements('', FALSE, TRUE);
module_implements_reset();
// Reset the Field API.
field_cache_clear();
......@@ -302,7 +302,7 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
}
// Reload hook implementations
module_implements('', FALSE, TRUE);
module_implements_reset();
// Rebuild caches.
drupal_static_reset();
......
......@@ -493,7 +493,7 @@ function system_install() {
// Clear out module list and hook implementation statics before calling
// system_rebuild_theme_data().
module_list(TRUE);
module_implements('', FALSE, TRUE);
module_implements_reset();
// Load system theme data appropriately.
system_rebuild_theme_data();
......
......@@ -367,7 +367,7 @@ function update_check_requirements() {
// Reset the module_implements() cache so that any new hook implementations
// in updated code are picked up.
module_implements('', FALSE, TRUE);
module_implements_reset();
// Set up $language, since the installer components require it.
drupal_language_initialize();
......
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