From 59ece2e39d28ba6052ea67d7770297b93a29d243 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Tue, 11 Nov 2008 22:39:59 +0000 Subject: - Patch #325665 by chx, Damien Tournoud, justinrandell et al: improved the cache registry lookups. --- includes/registry.inc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'includes/registry.inc') diff --git a/includes/registry.inc b/includes/registry.inc index c02811182..ec968dd2a 100644 --- a/includes/registry.inc +++ b/includes/registry.inc @@ -69,10 +69,26 @@ function _registry_rebuild() { ->execute(); } } - _registry_parse_files($files); + $parsed_files = _registry_parse_files($files); + + $unchanged_resources = array(); + foreach (_registry_get_lookup_cache() as $key => $file) { + // If the file for this cached resource is carried over unchanged from + // the last registry build, then we can safely re-cache it. + if ($file && in_array($file, array_keys($files)) && !in_array($file, $parsed_files)) { + $unchanged_resources[$key] = $file; + } + } + _registry_check_code(REGISTRY_RESET_LOOKUP_CACHE); module_implements(MODULE_IMPLEMENTS_CLEAR_CACHE); cache_clear_all('*', 'cache_registry', TRUE); + + // We have some unchanged resources, warm up the cache - no need to pay + // for looking them up again. + if (count($unchanged_resources) > 0) { + _registry_set_lookup_cache($unchanged_resources); + } } /** @@ -92,12 +108,13 @@ function registry_get_parsed_files() { * The list of files to check and parse. */ function _registry_parse_files($files) { - $changed_files = array(); + $parsed_files = array(); foreach ($files as $filename => $file) { $contents = file_get_contents($filename); $md5 = md5($contents); $new_file = !isset($file['md5']); if ($new_file || $md5 != $file['md5']) { + $parsed_files[] = $filename; // We update the md5 after we've saved the files resources rather than here, so if we // don't make it through this rebuild, the next run will reparse the file. _registry_parse_file($filename, $contents, $file['module'], $file['weight']); @@ -108,6 +125,7 @@ function _registry_parse_files($files) { ->execute(); } } + return $parsed_files; } /** -- cgit v1.2.3