Index: database/updates.inc =================================================================== RCS file: /cvs/drupal/drupal/database/updates.inc,v retrieving revision 1.100.2.9 diff -u -F^f -r1.100.2.9 updates.inc --- database/updates.inc 2 Dec 2005 21:32:31 -0000 1.100.2.9 +++ database/updates.inc 21 Jan 2006 18:04:22 -0000 @@ -107,7 +107,8 @@ "2005-03-21" => "update_128", "2005-04-14" => "update_129", "2005-05-06" => "update_130", - "2005-05-07" => "update_131" + "2005-05-07" => "update_131", + "2005-05-08" => "update_132" ); function update_32() { @@ -2394,6 +2395,19 @@ function update_131() { return $ret; } +function update_132() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {url_alias} ADD INDEX ('src')"); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("CREATE INDEX url_alias_src_idx ON {url_alias}(src)"); + } + + return $ret; +} + function update_sql($sql) { $edit = $_POST["edit"]; $result = db_query($sql); Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.44.2.2 diff -u -F^f -r1.44.2.2 bootstrap.inc --- includes/bootstrap.inc 30 Nov 2005 10:05:16 -0000 1.44.2.2 +++ includes/bootstrap.inc 21 Jan 2006 18:04:22 -0000 @@ -349,40 +349,70 @@ function drupal_load($type, $name) { } /** - * Return an array mapping path aliases to their internal Drupal paths. - */ -function drupal_get_path_map($action = '') { - static $map = NULL; - - if ($action == 'rebuild') { - $map = NULL; - } - - if (is_null($map)) { - $map = array(); // Make $map non-null in case no aliases are defined. - $result = db_query('SELECT * FROM {url_alias}'); - while ($data = db_fetch_object($result)) { - $map[$data->dst] = $data->src; + * Given an alias, return its Drupal system URL if one exists. Given a Drupal + * system URL return its alias if one exists. + * + * @param $action + * One of the following values: + * - wipe: delete the alias cache. + * - alias: return an alias for a given Drupal system path (if one exists). + * - source: return the Drupal system URL for a path alias (if one exists). + * @param $path + * The path to investigate for corresponding aliases or system URLs. + */ +function drupal_lookup_path($action, $path = '') { + static $map = array(); + static $count = NULL; + + + if ($count === NULL) { + $count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}')); + } + + if ($action == 'wipe') { + $map = array(); + } + elseif ($count > 0 && $path != '') { + if ($action == 'alias') { + if (isset($map[$path])) { + return $map[$path]; + } + if ($alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path))) { + $map[$path] = $alias; + return $alias; + } + else { + $map[$path] = $path; + } + } + elseif ($action == 'source') { + if ($alias = array_search($path, $map)) { + return $alias; + } + if (!isset($map[$path])) { + if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) { + $map[$src] = $path; + return $src; + } + } } } - return $map; + return FALSE; } /** * Given an internal Drupal path, return the alias set by the administrator. */ function drupal_get_path_alias($path) { - if (($map = drupal_get_path_map()) && ($newpath = array_search($path, $map))) { - return $newpath; - } - elseif (function_exists('conf_url_rewrite')) { - return conf_url_rewrite($path, 'outgoing'); + $result = $path; + if ($alias = drupal_lookup_path('alias', $path)) { + $result = $alias; } - else { - // No alias found. Return the normal path. - return $path; + if (function_exists('custom_url_rewrite')) { + $result = custom_url_rewrite('alias', $result, $path); } + return $result; } /** Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.434.2.16 diff -u -F^f -r1.434.2.16 common.inc --- includes/common.inc 2 Dec 2005 10:30:59 -0000 1.434.2.16 +++ includes/common.inc 21 Jan 2006 18:04:24 -0000 @@ -65,25 +65,17 @@ function drupal_get_html_head() { } /** - * Regenerate the path map from the information in the database. - */ -function drupal_rebuild_path_map() { - drupal_get_path_map('rebuild'); -} - -/** * Given a path alias, return the internal path it represents. */ function drupal_get_normal_path($path) { - if (($map = drupal_get_path_map()) && isset($map[$path])) { - return $map[$path]; + $result = $path; + if ($src = drupal_lookup_path('source', $path)) { + $result = $src; } - elseif (function_exists('conf_url_rewrite')) { - return conf_url_rewrite($path, 'incoming'); - } - else { - return $path; + if (function_exists('custom_url_rewrite')) { + $result = custom_url_rewrite('source', $result, $path); } + return $result; } /**