Index: includes/path.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/path.inc,v retrieving revision 1.37 diff -u -F^f -r1.37 path.inc --- includes/path.inc 26 May 2009 09:12:28 -0000 1.37 +++ includes/path.inc 30 May 2009 15:59:26 -0000 @@ -66,8 +66,23 @@ function drupal_lookup_path($action, $pa $count = NULL; $system_paths = array(); $no_aliases = array(); + + // For each alias in the database, get the top level (i.e. the portion before the first /). + // Using GROUP BY is faster than DISTINCT, at least for MyISAM. + $whitelist = array(); + $result = db_query("SELECT SUBSTRING_INDEX(src, '/', 1) AS path FROM {url_alias} GROUP BY path"); + foreach ($result as $row) { + $whitelist[$row->path] = TRUE; + } + variable_set('path_alias_whitelist', $whitelist); } elseif ($count > 0 && $path != '') { + // Retrieve the path alias whitelist + $whitelist = variable_get('path_alias_whitelist', array()); + // And derive the top level component of the path + $pos = strpos($path, '/'); + $top_level = ($pos) ? substr($path, 0, $pos) : $path; + if ($action == 'alias') { // During the first call to drupal_lookup_path() per language, load the // expected system paths for the page from cache. @@ -93,6 +108,12 @@ function drupal_lookup_path($action, $pa if (isset($map[$path_language][$path])) { return $map[$path_language][$path]; } + elseif (!isset($whitelist[$top_level])) { + // Check the path whitelist, if the top_level part before the first / + // is not in the list, then there is no need to do anything further, + // it is not in the database + return FALSE; + } // For system paths which were not cached, query aliases individually. else if (!isset($no_aliases[$path_language][$path])) { // Get the most fitting result falling back with alias without language