diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-03-07 06:58:14 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-03-07 06:58:14 +0000 |
commit | 8ba741dc49816476517b73ec83af9a1fc47619b3 (patch) | |
tree | 28a8c10e744b77167b569356dc7b8664b2f5db80 | |
parent | 3604231dd1d7eca9e650b743bdcad811e83d0afb (diff) | |
download | brdo-8ba741dc49816476517b73ec83af9a1fc47619b3.tar.gz brdo-8ba741dc49816476517b73ec83af9a1fc47619b3.tar.bz2 |
#723634 by catch: Improve path_save() performance.
-rw-r--r-- | includes/common.inc | 7 | ||||
-rw-r--r-- | includes/path.inc | 33 |
2 files changed, 28 insertions, 12 deletions
diff --git a/includes/common.inc b/includes/common.inc index 023bb516f..2c052dc3a 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -340,13 +340,6 @@ function drupal_get_html_head() { } /** - * Reset the static variable which holds the aliases mapped for this request. - */ -function drupal_clear_path_cache() { - drupal_lookup_path('wipe'); -} - -/** * Add a feed URL for the current page. * * This function can be called as long the HTML header hasn't been sent. diff --git a/includes/path.inc b/includes/path.inc index 8585a3b78..35a8dcffb 100644 --- a/includes/path.inc +++ b/includes/path.inc @@ -394,13 +394,24 @@ function current_path() { /** * Rebuild the path alias white list. * + * @param $source + * An optional system path for which an alias is being inserted. + * * @return * An array containing a white list of path aliases. */ -function drupal_path_alias_whitelist_rebuild() { +function drupal_path_alias_whitelist_rebuild($source = NULL) { + // When paths are inserted, only rebuild the whitelist if the system path + // has a top level component which is not already in the whitelist. + if (!empty($source)) { + $whitelist = variable_get('path_alias_whitelist', NULL); + if (isset($whitelist[strtok($source, '/')])) { + return $whitelist; + } + } // For each alias in the database, get the top level component of the system - // path it corresponds to. This is the portion of the path before the first / - // if present, otherwise the whole path itself. + // path it corresponds to. This is the portion of the path before the first + // '/', if present, otherwise the whole path itself. $whitelist = array(); $result = db_query("SELECT SUBSTRING_INDEX(source, '/', 1) AS path FROM {url_alias} GROUP BY path"); foreach ($result as $row) { @@ -469,7 +480,7 @@ function path_save(&$path) { else { module_invoke_all('path_update', $path); } - drupal_clear_path_cache(); + drupal_clear_path_cache($path['source']); } } @@ -490,7 +501,7 @@ function path_delete($criteria) { } $query->execute(); module_invoke_all('path_delete', $path); - drupal_clear_path_cache(); + drupal_clear_path_cache($path['source']); } /** @@ -591,3 +602,15 @@ function drupal_valid_path($path, $dynamic_allowed = FALSE) { $menu_admin = FALSE; return $item && $item['access']; } + +/** + * Clear the path cache. + * + * @param $source + * An optional system path for which an alias is being changed. + */ +function drupal_clear_path_cache($source = NULL) { + // Clear the drupal_lookup_path() static cache. + drupal_static_reset('drupal_lookup_path'); + drupal_path_alias_whitelist_rebuild($source); +} |