Index: includes/path.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/path.inc,v retrieving revision 1.15 diff -u -r1.15 path.inc --- includes/path.inc 26 Mar 2007 01:32:22 -0000 1.15 +++ includes/path.inc 5 Apr 2007 03:13:51 -0000 @@ -45,12 +45,12 @@ */ 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 + // $map is an array with language keys, holding arrays of Drupal paths to alias relations. static $map = array(), $no_src = array(), $count; $path_language = $path_language ? $path_language : $language->language; - // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases + // 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}')); } @@ -60,19 +60,35 @@ $no_src = array(); } elseif ($count > 0 && $path != '') { + static $optimize_type, $list; + + // Check if we should use the blacklist, the whitelist, or none of both. + if (!isset($optimize_type)) { + $optimize_type = variable_get('path_optimization_type', 2); + // We do not need to specify a default here, as you need to change + // the default optimize_type on the settings screen and then the + // variable will be saved anyways. + $list = variable_get('path_optimization_list', ''); + } + 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)); + // Get the most fitting result falling back with alias without language. + $query = "SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC"; + // If optimize_type is 1, it's whitelisting -- in this case we want to + // run the query when there is a match with the path. If optimize_type + // is 0 then we want to look up only if there is no match. If + // optimize_type is 2, then we always want to look up. + $alias = ($optimize_type == 2 || drupal_path_match($path, $list) == $optimize_type) ? db_result(db_query($query, $path, $path_language)) : FALSE; $map[$path_language][$path] = $alias; return $alias; } // Check $no_src for this $path in case we've already determined that there - // isn't a path that has this alias + // 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 + // 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 @@ -222,3 +238,23 @@ // we can check it against the 'site_frontpage' variable. return $_GET['q'] == drupal_get_normal_path(variable_get('site_frontpage', 'node')); } + +/** + * Check if a path matches a set of patterns. + * + * @param $path + * The path to match. + * @param $patterns + * String containing a set of patterns separated by \n, \r or \r\n. + * + * @return + * Boolean value: TRUE if the path matches a pattern, FALSE if otherwise. + */ +function drupal_path_match($path, $patterns) { + static $regexps; + + if (!isset($regexps[$patterns])) { + $regexps[$patterns] = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($patterns, '/')) .')$/'; + } + return preg_match($regexps[$patterns], $path); +} Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.254 diff -u -r1.254 block.module --- modules/block/block.module 27 Mar 2007 05:13:53 -0000 1.254 +++ modules/block/block.module 5 Apr 2007 03:14:01 -0000 @@ -691,11 +691,10 @@ if ($block->pages) { if ($block->visibility < 2) { $path = drupal_get_path_alias($_GET['q']); - $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/'; // Compare with the internal and path alias (if any). - $page_match = preg_match($regexp, $path); + $page_match = drupal_path_match($path, $block->pages); if ($path != $_GET['q']) { - $page_match = $page_match || preg_match($regexp, $_GET['q']); + $page_match = $page_match || drupal_path_match($_GET['q'], $block->pages); } // When $block->visibility has a value of 0, the block is displayed on // all pages except those listed in $block->pages. When set to 1, it Index: modules/path/path.module =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.module,v retrieving revision 1.113 diff -u -r1.113 path.module --- modules/path/path.module 27 Mar 2007 05:13:54 -0000 1.113 +++ modules/path/path.module 5 Apr 2007 03:14:04 -0000 @@ -27,7 +27,7 @@ return $output; case 'admin/build/path': case 'admin/build/path/list': - return '

'. t("Drupal provides users complete control over URLs through aliasing. This feature is typically used to make URLs human-readable or easy to remember. For example, one could map the relative URL 'node/1' onto 'about'. Each system path can have multiple aliases.") .'

'; + return '

'. t("Drupal provides users complete control over URLs through aliasing. This feature is typically used to make URLs human-readable or easy to remember. For example, one could map the relative URL 'node/1' onto 'about'. Each system path can have multiple aliases.") .'

'. t('Optimization via white/blacklisting URL alias lookups is available on the performance settings page.', array('@link' => url('admin/settings/performance'))) .'

'; case 'admin/build/path/add': return '

'. t('Enter the path you wish to create the alias for, followed by the name of the new alias.') .'

'; } @@ -297,6 +297,31 @@ ); } } + if ($form_id == 'system_performance_settings') { + $form['optimize'] = array( + '#type' => 'fieldset', + '#title' => t('Path optimization settings'), + '#collapsible' => false, + '#collapsed' => false, + '#weight' => -5, + ); + $form['optimize']['explanation'] = array( + '#value' => t("Path alias lookups can be fine tuned here. By setting certain paths which are known to not have aliases (blacklist) or restricting lookups to the (few) paths that are known to have aliases (whitelist) the number of database queries will be greatly reduced, saving system resources. For more information, see
the handbook."), + ); + $form['optimize']['path_optimization_type'] = array( + '#type' => 'radios', + '#title' => t('Optimization type'), + '#default_value' => variable_get('path_optimization_type', 2), + '#options' => array(t('Blacklist of Drupal paths'), t('Whitelist of Drupal paths'), t('No optimization')), + ); + $form['optimize']['path_optimization_list'] = array( + '#type' => 'textarea', + '#title' => t('List of paths'), + '#default_value' => variable_get('path_optimization_list', "admin*\n*/add*\*/edit\n*/outline\n*/revisions\n*/track\nadmin\nadmin/*\nbook\ncomment/*\nfilter\nfilter/*\nlogout\npoll\nprofile\ntracker*\nuser\nuser/register\nuser/login"), + '#rows' => 10, + '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page. A default is provided which is useful for blacklisting.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')), + ); + } } Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.460 diff -u -r1.460 system.module --- modules/system/system.module 27 Mar 2007 05:13:54 -0000 1.460 +++ modules/system/system.module 5 Apr 2007 03:14:21 -0000 @@ -668,6 +668,7 @@ '#type' => 'fieldset', '#title' => t('Page cache'), '#description' => t('Enabling the cache will offer a significant performance boost. Drupal can store and send compressed cached pages requested by anonymous users. By caching a web page, Drupal does not have to construct the page each time someone wants to view it.'), + '#weight' => -15, ); $form['page_cache']['cache'] = array( @@ -691,7 +692,8 @@ $form['bandwidth_optimizations'] = array( '#type' => 'fieldset', '#title' => t('Bandwidth optimizations'), - '#description' => t('These options can help reduce both the size and number of requests made to your website. This can reduce the server load, the bandwidth used, and the average page loading time for your visitors.') + '#description' => t('These options can help reduce both the size and number of requests made to your website. This can reduce the server load, the bandwidth used, and the average page loading time for your visitors.'), + '#weight' => -10, ); $directory = file_directory_path();