diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 35c9e0c..0c800d0 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -3155,11 +3155,24 @@ function registry_rebuild() { * to be called, because it is already known that the list of files in the * {system} table matches those in the file system. * + * @return + * TRUE if the registry was rebuilt, FALSE if another thread was rebuilding + * in parallel and the current thread just waited for completion. + * * @see registry_rebuild() */ function registry_update() { + if (!lock_acquire(__FUNCTION__)) { + // Wait for another request that is already doing this work. + lock_wait(__FUNCTION__); + return FALSE; + } + require_once DRUPAL_ROOT . '/core/includes/registry.inc'; _registry_update(); + + lock_release(__FUNCTION__); + return TRUE; } /** diff --git a/core/includes/registry.inc b/core/includes/registry.inc index 2ddd1f7..9abc3ee 100644 --- a/core/includes/registry.inc +++ b/core/includes/registry.inc @@ -156,9 +156,9 @@ function _registry_parse_files($files) { * Parse a file and save its function and class listings. * * @param $filename - * Name of the file we are going to parse. + * Name of the file we are going to parse. * @param $contents - * Contents of the file we are going to parse as a string. + * Contents of the file we are going to parse as a string. * @param $module * (optional) Name of the module this file belongs to. * @param $weight @@ -166,17 +166,19 @@ function _registry_parse_files($files) { */ function _registry_parse_file($filename, $contents, $module = '', $weight = 0) { if (preg_match_all('/^\s*(?:abstract|final)?\s*(class|interface)\s+([a-zA-Z0-9_]+)/m', $contents, $matches)) { - $query = db_insert('registry')->fields(array('name', 'type', 'filename', 'module', 'weight')); foreach ($matches[2] as $key => $name) { - $query->values(array( - 'name' => $name, - 'type' => $matches[1][$key], - 'filename' => $filename, - 'module' => $module, - 'weight' => $weight, - )); + db_merge('registry') + ->key(array( + 'name' => $name, + 'type' => $matches[1][$key], + )) + ->fields(array( + 'filename' => $filename, + 'module' => $module, + 'weight' => $weight, + )) + ->execute(); } - $query->execute(); } }