diff -urp ./includes/common.inc ../drupal-6.2-patched/includes/common.inc --- ./includes/common.inc 2008-04-09 21:11:44.000000000 +0000 +++ ../drupal-6.2-patched/includes/common.inc 2008-05-13 15:45:46.000000000 +0000 @@ -1463,6 +1463,7 @@ function drupal_page_footer() { if (variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) { page_set_cache(); } + drupal_lookup_path('cache'); module_invoke_all('exit'); } diff -urp ./includes/path.inc ../drupal-6.2-patched/includes/path.inc --- ./includes/path.inc 2007-11-04 16:42:45.000000000 +0000 +++ ../drupal-6.2-patched/includes/path.inc 2008-05-13 15:45:46.000000000 +0000 @@ -45,51 +45,103 @@ function drupal_init_path() { */ function drupal_lookup_path($action, $path = '', $path_language = '') { global $language; - // $map is an array with language keys, holding arrays of Drupal paths to alias relations - static $map = array(), $no_src = array(), $count; + static + $map, $no_src, + $map_dirty = FALSE, $no_src_dirty = FALSE, + $count, $expire = 0; + global $base_root; $path_language = $path_language ? $path_language : $language->language; // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases if (!isset($count)) { - $count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}')); + $count = db_result(db_query('SELECT COUNT(*) FROM {url_alias}')); } + if ($count == 0) { + return FALSE; + } + if (!isset($map)) { + $cache = cache_get('map_'. $base_root . request_uri(), 'cache_path'); + if ($cache) { + // FIXME: Why isn't un/serialization consistant? + if (is_array($cache->data)) { + $map = $cache->data; + } + else { + $map = unserialize($cache->data); + } + $expire = $cache->expire; + } + else { + $map = array(); + } - if ($action == 'wipe') { - $map = array(); - $no_src = array(); - } - elseif ($count > 0 && $path != '') { - if ($action == 'alias') { - if (isset($map[$path_language][$path])) { - return $map[$path_language][$path]; - } - // Get the most fitting result falling back with alias without language - $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language)); - $map[$path_language][$path] = $alias; - return $alias; + $cache = cache_get('no_src_'. $base_root . request_uri(), 'cache_path'); + if ($cache) { + // FIXME: Why isn't un/serialization consistant? + if (is_array($cache->data)) { + $no_src = $cache->data; + } + else { + $no_src = unserialize($cache->data); + } + $expire = $cache->expire; } - // Check $no_src for this $path in case we've already determined that there - // isn't a path that has this alias - elseif ($action == 'source' && !isset($no_src[$path_language][$path])) { - // Look for the value $path within the cached $map - $src = ''; - if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) { - // Get the most fitting result falling back with alias without language - if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language))) { - $map[$path_language][$src] = $path; + else { + $no_src = array(); + } + } + switch ($action) { + case 'alias': + if ($count > 0 && $path) { + if (isset($map[$path])) { + return $map[$path]; + } + if (!$alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path))) { + $alias = FALSE; + } + $map[$path] = $alias; + $map_dirty = TRUE; + return $alias; } - else { - // We can't record anything into $map because we do not have a valid - // index and there is no need because we have not learned anything - // about any Drupal path. Thus cache to $no_src. - $no_src[$path_language][$path] = TRUE; + break; + case 'source': + // Check $no_src for this $path in case we've already determined that there + // isn't a path that has this alias + if ($count > 0 && $path && !isset($no_src[$path])) { + if (!$src = array_search($path, $map)) { + if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) { + $map[$src] = $path; + $map_dirty = TRUE; + } + else { + // We can't record anything into $map because we do not have a valid + // index and there is no need because we have not learned anything + // about any Drupal path. Thus cache to $no_src. + $no_src[$path] = TRUE; + $no_src_dirty = TRUE; + return FALSE; + } } + return $src; } - return $src; - } + break; + case 'wipe': + $map = array(); + $no_src = array(); + break; + case 'cache': + if (!$expire) { + $expire = time() + (60 * 60 * 24); + } + if ($map_dirty) { + cache_set('map_'. $base_root . request_uri(), $map, 'cache_path', $expire); + } + if ($no_src_dirty) { + cache_set('no_src_' . $base_root . request_uri(), $no_src, 'cache_path', $expire); + } + break; } - return FALSE; } diff -urp ./modules/path/path.module ../drupal-6.2-patched/modules/path/path.module --- ./modules/path/path.module 2008-04-09 21:11:48.000000000 +0000 +++ ../drupal-6.2-patched/modules/path/path.module 2008-05-13 15:45:46.000000000 +0000 @@ -122,6 +122,7 @@ function path_set_alias($path = NULL, $a } } drupal_clear_path_cache(); + cache_clear_all(NULL, 'cache_path'); } Only in ../drupal-6.2-patched/modules/path: path.module.orig