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

Diff of /contributions/modules/advcache/DRUPAL-5-6/all_patches.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:12 2009 UTC
# Line 0  Line 1 
1    diff -Naur ../drupal/modules/block/block.module ./modules/block/block.module
2    --- ../drupal/modules/block/block.module        2007-09-12 03:49:35.000000000 -0400
3    +++ ./modules/block/block.module        2007-12-10 12:33:03.482126894 -0500
4    @@ -286,6 +286,7 @@
5       }
6       drupal_set_message(t('The block settings have been updated.'));
7       cache_clear_all();
8    +  cache_clear_all('*', 'cache_advcache_block', TRUE);
9     }
10    
11     /**
12    @@ -500,6 +501,7 @@
13         module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values);
14         drupal_set_message(t('The block configuration has been saved.'));
15         cache_clear_all();
16    +    cache_clear_all('*', 'cache_advcache_block', TRUE);
17         return 'admin/build/block';
18       }
19     }
20    @@ -538,6 +540,7 @@
21       db_query("DELETE FROM {blocks} WHERE module = 'block' AND delta = %d", $form_values['bid']);
22       drupal_set_message(t('The block %name has been removed.', array('%name' => $form_values['info'])));
23       cache_clear_all();
24    +  cache_clear_all('*', 'cache_advcache_block', TRUE);
25       return 'admin/build/block';
26     };
27    
28    @@ -643,26 +646,39 @@
29       static $blocks = array();
30    
31       if (!count($blocks)) {
32    -    $rids = array_keys($user->roles);
33    -    $placeholders = implode(',', array_fill(0, count($rids), '%d'));
34    -    $result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN ($placeholders) OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", array_merge(array($theme_key), $rids));
35    -    while ($block = db_fetch_object($result)) {
36    -      if (!isset($blocks[$block->region])) {
37    -        $blocks[$block->region] = array();
38    -      }
39    -      // Use the user's block visibility setting, if necessary
40    -      if ($block->custom != 0) {
41    -        if ($user->uid && isset($user->block[$block->module][$block->delta])) {
42    -          $enabled = $user->block[$block->module][$block->delta];
43    +    $cache_key = $user->uid. '::'. $theme_key;
44    +    $cache = cache_get($cache_key, 'cache_advcache_block');
45    +    $enabled_blocks = unserialize($cache->data);
46    +    if (empty($enabled_blocks)) {
47    +      $enabled_blocks = array();
48    +      $rids = array_keys($user->roles);
49    +      $placeholders = implode(',', array_fill(0, count($rids), '%d'));
50    +      $result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN ($placeholders) OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", array_merge(array($theme_key), $rids));
51    +      while ($block = db_fetch_object($result)) {
52    +        if (!isset($blocks[$block->region])) {
53    +          $blocks[$block->region] = array();
54    +        }
55    +        // Use the user's block visibility setting, if necessary
56    +        if ($block->custom != 0) {
57    +          if ($user->uid && isset($user->block[$block->module][$block->delta])) {
58    +            $enabled = $user->block[$block->module][$block->delta];
59    +          }
60    +          else {
61    +            $enabled = ($block->custom == 1);
62    +          }
63    +
64             }
65             else {
66    -          $enabled = ($block->custom == 1);
67    +          $enabled = TRUE;
68    +        }
69    +        if ($enabled) {
70    +          $enabled_blocks[] = $block;
71             }
72           }
73    -      else {
74    -        $enabled = TRUE;
75    -      }
76    +      cache_set($cache_key, 'cache_advcache_block', serialize($enabled_blocks));
77    +    }
78    
79    +    foreach ($enabled_blocks as $block) {
80           // Match path if necessary
81           if ($block->pages) {
82             if ($block->visibility < 2) {
83    @@ -686,7 +702,7 @@
84             $page_match = TRUE;
85           }
86    
87    -      if ($enabled && $page_match) {
88    +      if ($page_match) {
89             // Check the current throttle status and see if block should be displayed
90             // based on server load.
91             if (!($block->throttle && (module_invoke('throttle', 'status') > 0))) {
92    diff -Naur ../drupal/modules/comment/comment.module ./modules/comment/comment.module
93    --- ../drupal/modules/comment/comment.module    2007-11-07 03:03:30.000000000 -0500
94    +++ ./modules/comment/comment.module    2007-12-10 12:33:36.484007596 -0500
95    @@ -931,6 +931,16 @@
96     function comment_render($node, $cid = 0) {
97       global $user;
98    
99    +  // If this is an authenticated user who only has one role and cannot admin-
100    +  // ister comments, look for a cached copy of the comment, or in the case
101    +  // of $cid = 0, the whole tree of comments.
102    +  $cache_key = 0;
103    +  if (!user_access('administer comments') && count($user->roles) === 1 && in_array('authenticated user', $user->roles)) {
104    +    // Must accommodate pagination
105    +    $page = isset($_GET['page']) ? $_GET['page'] : '';
106    +    $cache_key = 'nid-'. $node->nid. '::cid-'. $cid. '::'. $page;
107    +  }
108    +
109       $output = '';
110    
111       if (user_access('access comments')) {
112    @@ -945,6 +955,12 @@
113         $comments_per_page = _comment_get_display_setting('comments_per_page');
114    
115         if ($cid) {
116    +      if ($cache_key) {
117    +        $cache = cache_get($cache_key, 'cache_comment');
118    +        $comment = unserialize($cache->data);
119    +      }
120    +
121    +      if (!$comment) {
122           // Single comment view.
123           $query = 'SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d';
124           $query_args = array($cid);
125    @@ -963,11 +979,26 @@
126               $function = $module .'_link_alter';
127               $function($node, $links);
128             }
129    +        }
130    +      }
131    
132    +      if ($comment) {
133             $output .= theme('comment_view', $comment, $links);
134           }
135         }
136         else {
137    +      if ($cache_key) {
138    +        if ($cache = cache_get($cache_key, 'cache_comment')) {
139    +          $comments = unserialize($cache->data);
140    +          $comment_count = count($comments);
141    +
142    +          // Get the pager
143    +          $cache = cache_get($cache_key. '::pager', 'cache_comment');
144    +          $pager = $cache->data;
145    +        }
146    +      }
147    +
148    +      if (empty($comments)) {
149           // Multiple comment view
150           $query_count = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d';
151           $query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d';
152    @@ -1002,21 +1033,32 @@
153               $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
154             }
155           }
156    -
157           // Start a form, for use with comment control.
158           $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args);
159    -      if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
160    +        $comment_count = db_num_rows($result);
161    +      }
162    +
163    +
164    +      if ($comment_count && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
165             $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
166           }
167    
168           $divs = 0;
169           $last_depth = 0;
170           drupal_add_css(drupal_get_path('module', 'comment') .'/comment.css');
171    +
172    +      if (empty($comments)) {
173    +        $comments = array();
174           while ($comment = db_fetch_object($result)) {
175             $comment = drupal_unpack($comment);
176             $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
177             $comment->depth = count(explode('.', $comment->thread)) - 1;
178    +          $comments[] = $comment;
179    +        }
180    +        cache_set($cache_key, 'cache_comment', serialize($comments));
181    +      }
182    
183    +      foreach ($comments as $comment) {
184             if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
185               if ($comment->depth > $last_depth) {
186                 $divs++;
187    @@ -1048,9 +1090,15 @@
188           for ($i = 0; $i < $divs; $i++) {
189             $output .= '</div>';
190           }
191    -      $output .= theme('pager', NULL, $comments_per_page, 0);
192    
193    -      if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
194    +      if (empty($pager)) {
195    +        $pager = theme('pager', NULL, $comments_per_page, 0);
196    +        cache_set($cache_key. '::pager', 'cache_comment', $pager);
197    +      }
198    +
199    +      $output .= $pager;
200    +
201    +      if ($comment_count && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
202             $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
203           }
204         }
205    @@ -2012,4 +2060,3 @@
206     function vancode2int($c = '00') {
207       return base_convert(substr($c, 1), 36, 10);
208     }
209    -
210    diff -Naur ../drupal/modules/node/node.module ./modules/node/node.module
211    --- ../drupal/modules/node/node.module  2007-09-29 19:41:28.000000000 -0400
212    +++ ./modules/node/node.module  2007-12-10 12:33:36.484007596 -0500
213    @@ -2463,7 +2463,7 @@
214     /**
215      * Menu callback; view a single node.
216      */
217    -function node_page_view($node, $cid = NULL) {
218    +function node_page_view($node, $cid = 0) {
219       drupal_set_title(check_plain($node->title));
220       return node_show($node, $cid);
221     }
222    diff -Naur ../drupal/modules/forum/forum.module ./modules/forum/forum.module
223    --- ../drupal/modules/forum/forum.module        2007-08-08 02:27:22.000000000 -0400
224    +++ ./modules/forum/forum.module        2007-12-10 12:34:14.986201561 -0500
225    @@ -709,6 +709,17 @@
226      */
227     function forum_get_forums($tid = 0) {
228    
229    +  // This caching breaks forum access! The results of db_rewrite_sql will
230    +  // be cached, meaning the first user to load this node after a cache
231    +  // refresh will set the permissions for everyone. If you are using a module
232    +  // that does query rewriting on forum queries, don't use this patch.
233    +  // If you're not sure whether or not this is the case, don't use this patch!
234    +  $cache = cache_get('forums::'. $tid, 'cache_forum');
235    +  if ($cache) {
236    +    $forums = unserialize($cache->data);
237    +    return $forums;
238    +  }
239    +
240       $forums = array();
241       $_forums = taxonomy_get_tree(variable_get('forum_nav_vocabulary', ''), $tid);
242    
243    @@ -754,6 +765,8 @@
244         $forums[$forum->tid] = $forum;
245       }
246    
247    +  cache_set('forums::'. $tid, 'cache_forum', serialize($forums));
248    +
249       return $forums;
250     }
251    
252    diff -Naur ../drupal/modules/node/node.module ./modules/node/node.module
253    --- ../drupal/modules/node/node.module  2007-09-29 19:41:28.000000000 -0400
254    +++ ./modules/node/node.module  2007-12-10 12:35:15.489649433 -0500
255    @@ -501,17 +501,31 @@
256      *   A fully-populated node object.
257      */
258     function node_load($param = array(), $revision = NULL, $reset = NULL) {
259    +  global $user;
260       static $nodes = array();
261    
262       if ($reset) {
263         $nodes = array();
264       }
265    
266    -  $cachable = ($revision == NULL);
267    +  $cache_id = 0;
268       $arguments = array();
269       if (is_numeric($param)) {
270    -    if ($cachable && isset($nodes[$param])) {
271    -      return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
272    +    if (module_exists('advcache')) {
273    +      $cache_id = ($revision == NULL) ? $param. '::'. advcache_array2int($user->roles) : 0;
274    +    }
275    +    if ($cache_id > 0) {
276    +      if (isset($nodes[$param])) {
277    +        return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
278    +      }
279    +      if ($user->uid != 1) {
280    +        $cache = cache_get($cache_id, 'cache_node');
281    +        if ($cache) {
282    +          $cache = unserialize($cache->data);
283    +          $nodes[$param] = is_object($cache) ? drupal_clone($cache) : $cache;
284    +          return $nodes[$param];
285    +        }
286    +      }
287         }
288         $cond = 'n.nid = %d';
289         $arguments[] = $param;
290    @@ -549,8 +563,13 @@
291             $node->$key = $value;
292           }
293         }
294    -    if ($cachable) {
295    +    if ($cache_id > 0) {
296           $nodes[$node->nid] = is_object($node) ? drupal_clone($node) : $node;
297    +      if ($user->uid != 1) {
298    +        if (!in_array($node->type, variable_get('advcache_node_exclude_types', array('poll')))) {
299    +          cache_set($cache_id, 'cache_node', serialize($nodes[$node->nid]));
300    +        }
301    +      }
302         }
303       }
304    
305    @@ -1973,8 +1992,8 @@
306       if (isset($node->body) && count(explode(' ', $node->body)) < $type->min_word_count) {
307         form_set_error('body', t('The body of your @type is too short. You need at least %words words.', array('%words' => $type->min_word_count, '@type' => $type->name)));
308       }
309    -
310    -  if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {
311    +  $changed = node_last_changed($node->nid);
312    +  if (isset($node->nid) && ($changed > $node->changed)) {
313         form_set_error('changed', t('This content has been modified by another user, changes cannot be saved.'));
314       }
315    
316    Index: includes/common.inc
317    ===================================================================
318    RCS file: /cvs/drupal/drupal/includes/common.inc,v
319    retrieving revision 1.611
320    diff -u -F^f -r1.611 common.inc
321    --- includes/common.inc 10 Jan 2007 23:30:07 -0000      1.611
322    +++ includes/common.inc 31 May 2007 16:29:16 -0000
323    @@ -1283,6 +1283,7 @@ function drupal_page_footer() {
324       if (variable_get('cache', 0)) {
325         page_set_cache();
326       }
327    +  drupal_lookup_path('cache');
328    
329       module_invoke_all('exit');
330     }
331    Index: includes/path.inc
332    ===================================================================
333    RCS file: /cvs/drupal/drupal/includes/path.inc,v
334    retrieving revision 1.13
335    diff -u -F^f -r1.13 path.inc
336    --- includes/path.inc   23 Dec 2006 22:04:52 -0000      1.13
337    +++ includes/path.inc   31 May 2007 16:29:16 -0000
338    @@ -32,6 +32,7 @@ function drupal_init_path() {
339      *   - wipe: delete the alias cache.
340      *   - alias: return an alias for a given Drupal system path (if one exists).
341      *   - source: return the Drupal system URL for a path alias (if one exists).
342    + *   - cache: (internal use only) save the maps into the cache_path table.
343      * @param $path
344      *   The path to investigate for corresponding aliases or system URLs.
345      *
346    @@ -41,44 +42,89 @@ function drupal_init_path() {
347      */
348     function drupal_lookup_path($action, $path = '') {
349       // $map keys are Drupal paths and the values are the corresponding aliases
350    -  static $map = array(), $no_src = array();
351    -  static $count;
352    +  static
353    +    $map, $no_src,
354    +    $map_dirty = FALSE, $no_src_dirty = FALSE,
355    +    $count, $expire = 0;
356    +  global $base_root;
357    
358       // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
359       if (!isset($count)) {
360    -    $count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}'));
361    +    $count = (int)db_result(db_query('SELECT pid FROM {url_alias} LIMIT 1'));
362       }
363    -
364    -  if ($action == 'wipe') {
365    -    $map = array();
366    -    $no_src = array();
367    +  if ($count == 0) {
368    +    return FALSE;
369       }
370    -  elseif ($count > 0 && $path != '') {
371    -    if ($action == 'alias') {
372    -      if (isset($map[$path])) {
373    -        return $map[$path];
374    +
375    +  if (!isset($map)) {
376    +    $cache = cache_get('map_'. $base_root . request_uri(), 'cache_path');
377    +    if ($cache) {
378    +      $map = unserialize($cache->data);
379    +      $expire = $cache->expire;
380           }
381    -      $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path));
382    -      $map[$path] = $alias;
383    -      return $alias;
384    +    else {
385    +      $map = array();
386    +    }
387    +
388    +    $cache = cache_get('no_src_'. $base_root . request_uri(), 'cache_path');
389    +    if ($cache) {
390    +      $no_src = unserialize($cache->data);
391    +      $expire = $cache->expire;
392    +    }
393    +    else {
394    +      $no_src = array();
395         }
396    -    // Check $no_src for this $path in case we've already determined that there
397    -    // isn't a path that has this alias
398    -    elseif ($action == 'source' && !isset($no_src[$path])) {
399    -      // Look for the value $path within the cached $map
400    -      if (!$src = array_search($path, $map)) {
401    -        if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) {
402    -          $map[$src] = $path;
403    +  }
404    +  switch ($action) {
405    +    case 'alias':
406    +      if ($count > 0 && $path) {
407    +        if (isset($map[$path])) {
408    +          return $map[$path];
409    +          }
410    +        if (!$alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path))) {
411    +          $alias = FALSE;
412    +          }
413    +        $map[$path] = $alias;
414    +        $map_dirty = TRUE;
415    +        return $alias;
416             }
417    -        else {
418    -          // We can't record anything into $map because we do not have a valid
419    -          // index and there is no need because we have not learned anything
420    -          // about any Drupal path. Thus cache to $no_src.
421    -          $no_src[$path] = TRUE;
422    +      break;
423    +    case 'source':
424    +      // Check $no_src for this $path in case we've already determined that there
425    +      // isn't a path that has this alias
426    +      if ($count > 0 && $path && !isset($no_src[$path])) {
427    +        if (!$src = array_search($path, $map)) {
428    +          if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) {
429    +            $map[$src] = $path;
430    +            $map_dirty = TRUE;
431    +          }
432    +          else {
433    +            // We can't record anything into $map because we do not have a valid
434    +            // index and there is no need because we have not learned anything
435    +            // about any Drupal path. Thus cache to $no_src.
436    +            $no_src[$path] = TRUE;
437    +            $no_src_dirty = TRUE;
438    +            return FALSE;
439    +          }
440             }
441    +        return $src;
442           }
443    -      return $src;
444    -    }
445    +      break;
446    +    case 'wipe':
447    +      $map = array();
448    +      $no_src = array();
449    +      break;
450    +    case 'cache':
451    +      if (!$expire) {
452    +        $expire = time() + (60 * 60 * 24);
453    +      }
454    +      if ($map_dirty) {
455    +        cache_set('map_'. $base_root . request_uri(), 'cache_path', serialize($map), $expire);
456    +      }
457    +      if ($no_src_dirty) {
458    +        cache_set('no_src_' . $base_root . request_uri(), 'cache_path', serialize($no_src), $expire);
459    +      }
460    +      break;
461       }
462    
463       return FALSE;
464    Index: modules/path/path.module
465    ===================================================================
466    RCS file: /cvs/drupal/drupal/modules/path/path.module,v
467    retrieving revision 1.105
468    diff -u -F^f -r1.105 path.module
469    --- modules/path/path.module    9 Jan 2007 08:34:03 -0000       1.105
470    +++ modules/path/path.module    31 May 2007 16:29:16 -0000
471    @@ -130,11 +130,9 @@ function path_admin_delete($pid = 0) {
472     function path_set_alias($path = NULL, $alias = NULL, $pid = NULL) {
473       if ($path && !$alias) {
474         db_query("DELETE FROM {url_alias} WHERE src = '%s'", $path);
475    -    drupal_clear_path_cache();
476       }
477       else if (!$path && $alias) {
478         db_query("DELETE FROM {url_alias} WHERE dst = '%s'", $alias);
479    -    drupal_clear_path_cache();
480       }
481       else if ($path && $alias) {
482         $path = urldecode($path);
483    @@ -145,7 +143,6 @@ function path_set_alias($path = NULL, $a
484         // We have an insert:
485         if ($path_count == 0 && $alias_count == 0) {
486           db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias);
487    -      drupal_clear_path_cache();
488         }
489         else if ($path_count >= 1 && $alias_count == 0) {
490           if ($pid) {
491    @@ -154,11 +151,9 @@ function path_set_alias($path = NULL, $a
492           else {
493             db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias);
494           }
495    -      drupal_clear_path_cache();
496         }
497         else if ($path_count == 0 && $alias_count == 1) {
498           db_query("UPDATE {url_alias} SET src = '%s' WHERE dst = '%s'", $path, $alias);
499    -      drupal_clear_path_cache();
500         }
501         else if ($path_count == 1 && $alias_count == 1) {
502           // This will delete the path that alias was originally pointing to:
503    @@ -167,6 +162,10 @@ function path_set_alias($path = NULL, $a
504           path_set_alias($path, $alias);
505         }
506       }
507    +
508    +  // Clear the static and the database cache.
509    +  drupal_clear_path_cache();
510    +  cache_clear_all(NULL, 'cache_path');
511     }
512    
513     /**
514    diff -Naur ../drupal/modules/search/search.module ./modules/search/search.module
515    --- ../drupal/modules/search/search.module      2007-07-26 15:16:48.000000000 -0400
516    +++ ./modules/search/search.module      2007-12-10 12:36:29.493866736 -0500
517    @@ -272,6 +272,8 @@
518         // When re-indexing, keep link references
519         db_query("DELETE FROM {search_index} WHERE sid = %d AND type = '%s'". ($reindex ? " AND fromsid = 0" : ''), $sid, $type);
520       }
521    +  // Cached search results may no longer be valid.
522    +  cache_clear_all(NULL, 'cache_search');
523     }
524    
525     /**
526    @@ -304,6 +306,34 @@
527       foreach (module_list() as $module) {
528         module_invoke($module, 'update_index');
529       }
530    +
531    +  // Don't allow search result caching if any node access modules such as organic
532    +  // groups have placed viewing restrictions on any nodes. Even if you have had
533    +  // organic groups enabled and have since disabled it, search caching will
534    +  // be prevented. If you find yourself in this position, you can restore the
535    +  // original un-restricted state of node_access like this:
536    +  // TRUNCATE node_access;
537    +  // INSERT INTO node_access VALUES (0,0,'all',1,0,0);
538    +  $r1 = db_result(db_query("SELECT count(*) FROM {node_access}"));
539    +  $r2 = db_result(db_query("SELECT count(*) FROM {node_access} WHERE grant_view = 1"));
540    +  if (($r1 == 1) && ($r2 == 1)) {
541    +    // Recalculate the list of popular search terms
542    +    $tops = array();
543    +    $result = db_query("SELECT location, count(*) AS count FROM {watchdog} WHERE type = 'search' GROUP BY location HAVING count(*) > 2");
544    +    while ($row = db_fetch_object($result)) {
545    +      $tops[] = strtolower($row->location);
546    +    }
547    +    // Since we just potentially indexed new or updated content, clear the cache.
548    +    cache_clear_all(NULL, 'cache_search');
549    +
550    +    // Set the search_cache_queries to the new top queries.
551    +    cache_set('search_cache_queries', 'cache_search', serialize($tops));
552    +  }
553    +  else {
554    +    // No guarantee that the cache complies with node access restrictions, so
555    +    // wipe it.
556    +    cache_clear_all(NULL, 'cache_search');
557    +  }
558     }
559    
560     /**
561    @@ -890,6 +920,7 @@
562      * Menu callback; presents the search form and/or search results.
563      */
564     function search_view() {
565    +  global $base_root, $user;
566       $type = arg(1);
567    
568       // Search form submits with POST but redirects to GET. This way we can keep
569    @@ -909,8 +940,29 @@
570           // Log the search keys:
571           watchdog('search', t('%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name'))), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys));
572    
573    -      // Collect the search results:
574    -      $results = search_data($keys, $type);
575    +      // Look to the cache to see if this is a popular (thus cached) query
576    +      $request_uri = strtolower($base_root . request_uri());
577    +      $results = NULL;
578    +      // Only cache results if the user is not an admin, is authenticated, has
579    +      // exactly one role, and the query is in the popular search queries array.
580    +      if ($cachable = ($user->uid > 1 && count($user->roles) === 1 && in_array('authenticated user', $user->roles))) {
581    +        $queries_cache = cache_get('search_cache_queries', 'cache_search');
582    +      }
583    +      if ($cachable && $queries_cache) {
584    +        $search_cache_queries = unserialize($queries_cache->data);
585    +        if (in_array($request_uri, $search_cache_queries)) {
586    +          if ($search_cache = cache_get($request_uri, 'cache_search')) {
587    +            $results = $search_cache->data;
588    +          }
589    +        }
590    +      }
591    +      if (empty($results)) {
592    +        // Collect the search results:
593    +        $results = search_data($keys, $type);
594    +        if ($cachable) {
595    +          cache_set($request_uri, 'cache_search', $results);
596    +        }
597    +      }
598    
599           if ($results) {
600             $results = theme('box', t('Search results'), $results);
601    diff -Naur ../drupal/modules/taxonomy/taxonomy.module ./modules/taxonomy/taxonomy.module
602    --- ../drupal/modules/taxonomy/taxonomy.module  2007-12-06 13:16:38.000000000 -0500
603    +++ ./modules/taxonomy/taxonomy.module  2007-12-10 12:41:56.012473975 -0500
604    @@ -778,12 +778,25 @@
605       static $terms;
606    
607       if (!isset($terms[$nid][$key])) {
608    -    $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.nid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $nid);
609    -    $terms[$nid][$key] = array();
610    -    while ($term = db_fetch_object($result)) {
611    -      $terms[$nid][$key][$term->$key] = $term;
612    +    // This caching breaks taxonomy access! The results of db_rewrite_sql will
613    +    // be cached, meaning the first user to load this node after a cache
614    +    // refresh will set the permissions for everyone. If you are using a module
615    +    // that does query rewriting on taxonomy queries, don't use this patch.
616    +    // If you're not sure whether or not this is the case, don't use this patch!
617    +    $cache_key = 'node::'. $nid. '::'. $key;
618    +    if ($cache = cache_get($cache_key, 'cache_taxonomy')) {
619    +      $terms[$nid][$key] = unserialize($cache->data);
620    +    }
621    +    else {
622    +      $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.nid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $nid);
623    +      $terms[$nid][$key] = array();
624    +      while ($term = db_fetch_object($result)) {
625    +        $terms[$nid][$key][$term->$key] = $term;
626    +      }
627    +      cache_set($cache_key, 'cache_taxonomy', serialize($terms[$nid][$key]));
628         }
629       }
630    +
631       return $terms[$nid][$key];
632     }
633    
634    @@ -987,7 +1000,14 @@
635      */
636     function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL) {
637       static $children, $parents, $terms;
638    -
639    +  if ((0 === $parent) && (-1 === $depth)) {
640    +    if ($cache = cache_get('tree::'. $vid, 'cache_taxonomy')) {
641    +      return unserialize($cache->data);
642    +    }
643    +    else {
644    +      $cache_tree = TRUE;
645    +    }
646    +  }
647       $depth++;
648    
649       // We cache trees, so it's not CPU-intensive to call get_tree() on a term
650    @@ -1021,6 +1041,10 @@
651         }
652       }
653    
654    +  if ($cache_tree) {
655    +    cache_set('tree::'. $vid, 'cache_taxonomy', serialize($tree));
656    +  }
657    +
658       return $tree ? $tree : array();
659     }
660    
661    @@ -1143,13 +1167,19 @@
662       static $vocabularies = array();
663    
664       if (!array_key_exists($vid, $vocabularies)) {
665    -    $result = db_query('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.vid = %d ORDER BY v.weight, v.name', $vid);
666    -    $node_types = array();
667    -    while ($voc = db_fetch_object($result)) {
668    -      $node_types[] = $voc->type;
669    -      unset($voc->type);
670    -      $voc->nodes = $node_types;
671    -      $vocabularies[$vid] = $voc;
672    +    if ($cache = cache_get('vocabulary::'. $vid, 'cache_taxonomy')) {
673    +      $vocabularies[$vid] = unserialize($cache->data);
674    +    }
675    +    else {
676    +      $result = db_query('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.vid = %d ORDER BY v.weight, v.name', $vid);
677    +      $node_types = array();
678    +      while ($voc = db_fetch_object($result)) {
679    +        $node_types[] = $voc->type;
680    +        unset($voc->type);
681    +        $voc->nodes = $node_types;
682    +        $vocabularies[$vid] = $voc;
683    +        cache_set('vocabulary::'. $vid, 'cache_taxonomy', serialize($voc));
684    +      }
685         }
686       }
687    
688    @@ -1169,7 +1199,13 @@
689       static $terms = array();
690    
691       if (!isset($terms[$tid])) {
692    -    $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid));
693    +    if ($cache = cache_get('term::'. $tid, 'cache_taxonomy')) {
694    +      $terms[$tid] = unserialize($cache->data);
695    +    }
696    +    else {
697    +      $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid));
698    +      cache_set('term::'. $tid, 'cache_taxonomy', serialize($terms[$tid]));
699    +    }
700       }
701    
702       return $terms[$tid];
703    @@ -1298,8 +1334,8 @@
704     function taxonomy_nodeapi($node, $op, $arg = 0) {
705       switch ($op) {
706         case 'load':
707    -     $output['taxonomy'] = taxonomy_node_get_terms($node->nid);
708    -     return $output;
709    +      $output['taxonomy'] = taxonomy_node_get_terms($node->nid);
710    +      return $output;
711         case 'insert':
712           taxonomy_node_save($node->nid, $node->taxonomy);
713           break;

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

  ViewVC Help
Powered by ViewVC 1.1.3