| 1 |
Index: includes/path.inc
|
| 2 |
===================================================================
|
| 3 |
RCS file: /cvs/drupal/drupal/includes/path.inc,v
|
| 4 |
retrieving revision 1.19.2.1
|
| 5 |
diff -u -p -r1.19.2.1 path.inc
|
| 6 |
--- includes/path.inc 13 Oct 2008 21:06:41 -0000 1.19.2.1
|
| 7 |
+++ includes/path.inc 3 Dec 2008 20:55:49 -0000
|
| 8 |
@@ -50,6 +50,91 @@ function drupal_lookup_path($action, $pa
|
| 9 |
|
| 10 |
$path_language = $path_language ? $path_language : $language->language;
|
| 11 |
|
| 12 |
+ // ************* Begin pathcache.module Path Caching Modifications **************
|
| 13 |
+
|
| 14 |
+ // Drupal core checks to see if the url_alias table is empty on each request.
|
| 15 |
+ // We assume that the table is nonempty, since it would be very silly to enable
|
| 16 |
+ // the Path Cache module if you had no paths to cache. Thus, we have eliminated
|
| 17 |
+ // the $count variable altogether.
|
| 18 |
+ /*
|
| 19 |
+
|
| 20 |
+ // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
|
| 21 |
+ if (!isset($count)) {
|
| 22 |
+ $count = (int)db_result(db_query('SELECT pid FROM {url_alias} LIMIT 1'));
|
| 23 |
+ }
|
| 24 |
+ */
|
| 25 |
+
|
| 26 |
+ // A wipe is most commonly performed by path_set_alias() in path.module via
|
| 27 |
+ // drupal_clear_path_cache() in common.inc. The intent it to clear the static
|
| 28 |
+ // variables $map and $no_src, but we can also use it as an indicator that
|
| 29 |
+ // the path cache is dirty.
|
| 30 |
+ if ($action == 'wipe') {
|
| 31 |
+ $map = array();
|
| 32 |
+ $no_src = array();
|
| 33 |
+ // This will flush the entire cache_path cache.
|
| 34 |
+ // Drastic, but if running with a memcached caching backend, wildcards
|
| 35 |
+ // are not supported so the whole bin must be flushed.
|
| 36 |
+ cache_clear_all('*', 'cache_pathdst', TRUE);
|
| 37 |
+ cache_clear_all('*', 'cache_pathsrc', TRUE);
|
| 38 |
+ }
|
| 39 |
+ elseif ($path != '') {
|
| 40 |
+ // When action is 'alias' we are given a Drupal path and are looking to
|
| 41 |
+ // see if there is an alias for it.
|
| 42 |
+ if ($action == 'alias') {
|
| 43 |
+ // First check the static variable in case we've looked up this system path earlier
|
| 44 |
+ // in this request.
|
| 45 |
+ if (isset($map[$path_language][$path])) {
|
| 46 |
+ return $map[$path_language][$path];
|
| 47 |
+ }
|
| 48 |
+ // Not in the static variable. Try cache.
|
| 49 |
+ $cid = $path . $path_language;
|
| 50 |
+ $cache = cache_get($cid, 'cache_pathdst');
|
| 51 |
+ if ($cache) {
|
| 52 |
+ return $cache->data;
|
| 53 |
+ }
|
| 54 |
+ // Get the most fitting result falling back with alias without language.
|
| 55 |
+ $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC", $path, $path_language));
|
| 56 |
+ // Store in static variable in case we encounter the same system path again
|
| 57 |
+ // during this request.
|
| 58 |
+ $map[$path_language][$path] = $alias;
|
| 59 |
+ // Store in cache.
|
| 60 |
+ cache_set($cid, $alias, 'cache_pathdst', variable_get('pathcache_expire', 43200)); // 12 hours
|
| 61 |
+ return $alias;
|
| 62 |
+ }
|
| 63 |
+ // When action is 'source' we are given a URL alias and need to return the
|
| 64 |
+ // Drupal path.
|
| 65 |
+ // Check $no_src for this $path in case we've already determined that there
|
| 66 |
+ // isn't a path that has this alias.
|
| 67 |
+ elseif ($action == 'source' && !isset($no_src[$path_language][$path])) {
|
| 68 |
+ $src = '';
|
| 69 |
+ // Look for the value $path within the cached $map.
|
| 70 |
+ if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) {
|
| 71 |
+ $cid = $path . $path_language;
|
| 72 |
+ $cache = cache_get($cid, 'cache_pathsrc');
|
| 73 |
+ if ($cache) {
|
| 74 |
+ return $cache->data;
|
| 75 |
+ }
|
| 76 |
+
|
| 77 |
+ // Get the most fitting result falling back with alias without language
|
| 78 |
+ 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))) {
|
| 79 |
+ $map[$path_language][$src] = $path;
|
| 80 |
+ cache_set($cid, $src, 'cache_pathsrc', variable_get('pathcache_expire', 43200)); // 12 hours
|
| 81 |
+ }
|
| 82 |
+ else {
|
| 83 |
+ // We can't record anything into $map because we do not have a valid
|
| 84 |
+ // index and there is no need because we have not learned anything
|
| 85 |
+ // about any Drupal path. Thus cache to $no_src.
|
| 86 |
+ // Setting this flag makes the array_search($path, $map[$path_language]) test
|
| 87 |
+ // above false, and skips to return $src, below.
|
| 88 |
+ $no_src[$path_language][$path] = TRUE;
|
| 89 |
+ }
|
| 90 |
+ }
|
| 91 |
+ return $src;
|
| 92 |
+ }
|
| 93 |
+ }
|
| 94 |
+
|
| 95 |
+ return FALSE;
|
| 96 |
+ // ************** End pathcache.module Path Caching Modifications ***************
|
| 97 |
// Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
|
| 98 |
if (!isset($count)) {
|
| 99 |
$count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}'));
|