/[drupal]/contributions/modules/advcache/DRUPAL-5-6/path_cache.patch
ViewVC logotype

Diff of /contributions/modules/advcache/DRUPAL-5-6/path_cache.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by robertDouglass, Fri Jul 18 20:54:49 2008 UTC revision 1.2 by mikejoconnor, Thu Feb 26 13:39:13 2009 UTC
# Line 0  Line 1 
1    Index: includes/common.inc
2    ===================================================================
3    RCS file: /cvs/drupal/drupal/includes/common.inc,v
4    retrieving revision 1.611
5    diff -u -F^f -r1.611 common.inc
6    --- includes/common.inc 10 Jan 2007 23:30:07 -0000      1.611
7    +++ includes/common.inc 31 May 2007 16:29:16 -0000
8    @@ -1283,6 +1283,7 @@ function drupal_page_footer() {
9       if (variable_get('cache', 0)) {
10         page_set_cache();
11       }
12    +  drupal_lookup_path('cache');
13    
14       module_invoke_all('exit');
15     }
16    Index: includes/path.inc
17    ===================================================================
18    RCS file: /cvs/drupal/drupal/includes/path.inc,v
19    retrieving revision 1.13
20    diff -u -F^f -r1.13 path.inc
21    --- includes/path.inc   23 Dec 2006 22:04:52 -0000      1.13
22    +++ includes/path.inc   31 May 2007 16:29:16 -0000
23    @@ -32,6 +32,7 @@ function drupal_init_path() {
24      *   - wipe: delete the alias cache.
25      *   - alias: return an alias for a given Drupal system path (if one exists).
26      *   - source: return the Drupal system URL for a path alias (if one exists).
27    + *   - cache: (internal use only) save the maps into the cache_path table.
28      * @param $path
29      *   The path to investigate for corresponding aliases or system URLs.
30      *
31    @@ -41,44 +42,89 @@ function drupal_init_path() {
32      */
33     function drupal_lookup_path($action, $path = '') {
34       // $map keys are Drupal paths and the values are the corresponding aliases
35    -  static $map = array(), $no_src = array();
36    -  static $count;
37    +  static
38    +    $map, $no_src,
39    +    $map_dirty = FALSE, $no_src_dirty = FALSE,
40    +    $count, $expire = 0;
41    +  global $base_root;
42    
43       // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
44       if (!isset($count)) {
45    -    $count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}'));
46    +    $count = (int)db_result(db_query('SELECT pid FROM {url_alias} LIMIT 1'));
47       }
48    -
49    -  if ($action == 'wipe') {
50    -    $map = array();
51    -    $no_src = array();
52    +  if ($count == 0) {
53    +    return FALSE;
54       }
55    -  elseif ($count > 0 && $path != '') {
56    -    if ($action == 'alias') {
57    -      if (isset($map[$path])) {
58    -        return $map[$path];
59    +
60    +  if (!isset($map)) {
61    +    $cache = cache_get('map_'. $base_root . request_uri(), 'cache_path');
62    +    if ($cache) {
63    +      $map = unserialize($cache->data);
64    +      $expire = $cache->expire;
65           }
66    -      $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path));
67    -      $map[$path] = $alias;
68    -      return $alias;
69    +    else {
70    +      $map = array();
71    +    }
72    +
73    +    $cache = cache_get('no_src_'. $base_root . request_uri(), 'cache_path');
74    +    if ($cache) {
75    +      $no_src = unserialize($cache->data);
76    +      $expire = $cache->expire;
77    +    }
78    +    else {
79    +      $no_src = array();
80         }
81    -    // Check $no_src for this $path in case we've already determined that there
82    -    // isn't a path that has this alias
83    -    elseif ($action == 'source' && !isset($no_src[$path])) {
84    -      // Look for the value $path within the cached $map
85    -      if (!$src = array_search($path, $map)) {
86    -        if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) {
87    -          $map[$src] = $path;
88    +  }
89    +  switch ($action) {
90    +    case 'alias':
91    +      if ($count > 0 && $path) {
92    +        if (isset($map[$path])) {
93    +          return $map[$path];
94    +          }
95    +        if (!$alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path))) {
96    +          $alias = FALSE;
97    +          }
98    +        $map[$path] = $alias;
99    +        $map_dirty = TRUE;
100    +        return $alias;
101             }
102    -        else {
103    -          // We can't record anything into $map because we do not have a valid
104    -          // index and there is no need because we have not learned anything
105    -          // about any Drupal path. Thus cache to $no_src.
106    -          $no_src[$path] = TRUE;
107    +      break;
108    +    case 'source':
109    +      // Check $no_src for this $path in case we've already determined that there
110    +      // isn't a path that has this alias
111    +      if ($count > 0 && $path && !isset($no_src[$path])) {
112    +        if (!$src = array_search($path, $map)) {
113    +          if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) {
114    +            $map[$src] = $path;
115    +            $map_dirty = TRUE;
116    +          }
117    +          else {
118    +            // We can't record anything into $map because we do not have a valid
119    +            // index and there is no need because we have not learned anything
120    +            // about any Drupal path. Thus cache to $no_src.
121    +            $no_src[$path] = TRUE;
122    +            $no_src_dirty = TRUE;
123    +            return FALSE;
124    +          }
125             }
126    +        return $src;
127           }
128    -      return $src;
129    -    }
130    +      break;
131    +    case 'wipe':
132    +      $map = array();
133    +      $no_src = array();
134    +      break;
135    +    case 'cache':
136    +      if (!$expire) {
137    +        $expire = time() + (60 * 60 * 24);
138    +      }
139    +      if ($map_dirty) {
140    +        cache_set('map_'. $base_root . request_uri(), 'cache_path', serialize($map), $expire);
141    +      }
142    +      if ($no_src_dirty) {
143    +        cache_set('no_src_' . $base_root . request_uri(), 'cache_path', serialize($no_src), $expire);
144    +      }
145    +      break;
146       }
147    
148       return FALSE;
149    Index: modules/path/path.module
150    ===================================================================
151    RCS file: /cvs/drupal/drupal/modules/path/path.module,v
152    retrieving revision 1.105
153    diff -u -F^f -r1.105 path.module
154    --- modules/path/path.module    9 Jan 2007 08:34:03 -0000       1.105
155    +++ modules/path/path.module    31 May 2007 16:29:16 -0000
156    @@ -130,11 +130,9 @@ function path_admin_delete($pid = 0) {
157     function path_set_alias($path = NULL, $alias = NULL, $pid = NULL) {
158       if ($path && !$alias) {
159         db_query("DELETE FROM {url_alias} WHERE src = '%s'", $path);
160    -    drupal_clear_path_cache();
161       }
162       else if (!$path && $alias) {
163         db_query("DELETE FROM {url_alias} WHERE dst = '%s'", $alias);
164    -    drupal_clear_path_cache();
165       }
166       else if ($path && $alias) {
167         $path = urldecode($path);
168    @@ -145,7 +143,6 @@ function path_set_alias($path = NULL, $a
169         // We have an insert:
170         if ($path_count == 0 && $alias_count == 0) {
171           db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias);
172    -      drupal_clear_path_cache();
173         }
174         else if ($path_count >= 1 && $alias_count == 0) {
175           if ($pid) {
176    @@ -154,11 +151,9 @@ function path_set_alias($path = NULL, $a
177           else {
178             db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias);
179           }
180    -      drupal_clear_path_cache();
181         }
182         else if ($path_count == 0 && $alias_count == 1) {
183           db_query("UPDATE {url_alias} SET src = '%s' WHERE dst = '%s'", $path, $alias);
184    -      drupal_clear_path_cache();
185         }
186         else if ($path_count == 1 && $alias_count == 1) {
187           // This will delete the path that alias was originally pointing to:
188    @@ -167,6 +162,10 @@ function path_set_alias($path = NULL, $a
189           path_set_alias($path, $alias);
190         }
191       }
192    +
193    +  // Clear the static and the database cache.
194    +  drupal_clear_path_cache();
195    +  cache_clear_all(NULL, 'cache_path');
196     }
197    
198     /**

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.3