|
@@ -19,7 +19,6 @@
|
|
* Does the work for registry_update().
|
|
* Does the work for registry_update().
|
|
*/
|
|
*/
|
|
function _registry_update() {
|
|
function _registry_update() {
|
|
-
|
|
|
|
// The registry serves as a central autoloader for all classes, including
|
|
// The registry serves as a central autoloader for all classes, including
|
|
// the database query builders. However, the registry rebuild process
|
|
// the database query builders. However, the registry rebuild process
|
|
// requires write ability to the database, which means having access to the
|
|
// requires write ability to the database, which means having access to the
|
|
@@ -33,6 +32,11 @@ function _registry_update() {
|
|
require_once DRUPAL_ROOT . '/includes/database/select.inc';
|
|
require_once DRUPAL_ROOT . '/includes/database/select.inc';
|
|
require_once DRUPAL_ROOT . '/includes/database/' . $driver . '/query.inc';
|
|
require_once DRUPAL_ROOT . '/includes/database/' . $driver . '/query.inc';
|
|
|
|
|
|
|
|
+ // During the first registry rebuild in a request, we check all the files.
|
|
|
|
+ // During subsequent rebuilds, we only add new files. It makes the rebuilding
|
|
|
|
+ // process faster during installation of modules.
|
|
|
|
+ static $check_existing_files = TRUE;
|
|
|
|
+
|
|
// Get current list of modules and their files.
|
|
// Get current list of modules and their files.
|
|
$modules = db_query("SELECT * FROM {system} WHERE type = 'module'")->fetchAll();
|
|
$modules = db_query("SELECT * FROM {system} WHERE type = 'module'")->fetchAll();
|
|
// Get the list of files we are going to parse.
|
|
// Get the list of files we are going to parse.
|
|
@@ -55,6 +59,9 @@ function _registry_update() {
|
|
$files["$filename"] = array('module' => '', 'weight' => 0);
|
|
$files["$filename"] = array('module' => '', 'weight' => 0);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Initialize an empty array for the unchanged files.
|
|
|
|
+ $unchanged_files = array();
|
|
|
|
+
|
|
$transaction = db_transaction();
|
|
$transaction = db_transaction();
|
|
try {
|
|
try {
|
|
// Allow modules to manually modify the list of files before the registry
|
|
// Allow modules to manually modify the list of files before the registry
|
|
@@ -63,10 +70,19 @@ function _registry_update() {
|
|
// list can then be added to the list of files that the registry will parse,
|
|
// list can then be added to the list of files that the registry will parse,
|
|
// or modify attributes of a file.
|
|
// or modify attributes of a file.
|
|
drupal_alter('registry_files', $files, $modules);
|
|
drupal_alter('registry_files', $files, $modules);
|
|
|
|
+
|
|
foreach (registry_get_parsed_files() as $filename => $file) {
|
|
foreach (registry_get_parsed_files() as $filename => $file) {
|
|
// Add the hash for those files we have already parsed.
|
|
// Add the hash for those files we have already parsed.
|
|
if (isset($files[$filename])) {
|
|
if (isset($files[$filename])) {
|
|
- $files[$filename]['hash'] = $file['hash'];
|
|
|
|
|
|
+ if ($check_existing_files === TRUE) {
|
|
|
|
+ $files[$filename]['hash'] = $file['hash'];
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ // Ignore that file for this request, it has been parsed previously
|
|
|
|
+ // and it is unlikely it has changed.
|
|
|
|
+ unset($files[$filename]);
|
|
|
|
+ $unchanged_files[$filename] = $file;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
// Flush the registry of resources in files that are no longer on disc
|
|
// Flush the registry of resources in files that are no longer on disc
|
|
@@ -79,8 +95,12 @@ function _registry_update() {
|
|
->execute();
|
|
->execute();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
$parsed_files = _registry_parse_files($files);
|
|
$parsed_files = _registry_parse_files($files);
|
|
|
|
|
|
|
|
+ // Add unchanged files to the files.
|
|
|
|
+ $files += $unchanged_files;
|
|
|
|
+
|
|
$unchanged_resources = array();
|
|
$unchanged_resources = array();
|
|
$lookup_cache = array();
|
|
$lookup_cache = array();
|
|
if ($cache = cache_get('lookup_cache', 'cache_bootstrap')) {
|
|
if ($cache = cache_get('lookup_cache', 'cache_bootstrap')) {
|
|
@@ -89,12 +109,10 @@ function _registry_update() {
|
|
foreach ($lookup_cache as $key => $file) {
|
|
foreach ($lookup_cache as $key => $file) {
|
|
// If the file for this cached resource is carried over unchanged from
|
|
// If the file for this cached resource is carried over unchanged from
|
|
// the last registry build, then we can safely re-cache it.
|
|
// the last registry build, then we can safely re-cache it.
|
|
- if ($file && in_array($file, array_keys($files)) && !in_array($file, $parsed_files)) {
|
|
|
|
|
|
+ if ($file && isset($files[$file]) && !in_array($file, $parsed_files, TRUE)) {
|
|
$unchanged_resources[$key] = $file;
|
|
$unchanged_resources[$key] = $file;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- module_implements('', FALSE, TRUE);
|
|
|
|
- _registry_check_code(REGISTRY_RESET_LOOKUP_CACHE);
|
|
|
|
}
|
|
}
|
|
catch (Exception $e) {
|
|
catch (Exception $e) {
|
|
$transaction->rollback();
|
|
$transaction->rollback();
|
|
@@ -102,6 +120,13 @@ function _registry_update() {
|
|
throw $e;
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ module_implements('', FALSE, TRUE);
|
|
|
|
+ _registry_check_code(REGISTRY_RESET_LOOKUP_CACHE);
|
|
|
|
+
|
|
|
|
+ // During the next run in this request, don't bother re-checking existing
|
|
|
|
+ // files.
|
|
|
|
+ $check_existing_files = FALSE;
|
|
|
|
+
|
|
// We have some unchanged resources, warm up the cache - no need to pay
|
|
// We have some unchanged resources, warm up the cache - no need to pay
|
|
// for looking them up again.
|
|
// for looking them up again.
|
|
if (count($unchanged_resources) > 0) {
|
|
if (count($unchanged_resources) > 0) {
|