--- modules/block/block.module	2008-05-13 07:51:04.000000000 +0300
+++ modules/block/block.module.new	2008-07-20 16:08:57.100166595 +0300
@@ -286,6 +286,7 @@
   }
   drupal_set_message(t('The block settings have been updated.'));
   cache_clear_all();
+  cache_clear_all('*', 'cache_advcache_block', TRUE);
 }
 
 /**
@@ -500,6 +501,7 @@
     module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values);
     drupal_set_message(t('The block configuration has been saved.'));
     cache_clear_all();
+    cache_clear_all('*', 'cache_advcache_block', TRUE);
     return 'admin/build/block';
   }
 }
@@ -538,6 +540,7 @@
   db_query("DELETE FROM {blocks} WHERE module = 'block' AND delta = %d", $form_values['bid']);
   drupal_set_message(t('The block %name has been removed.', array('%name' => $form_values['info'])));
   cache_clear_all();
+  cache_clear_all('*', 'cache_advcache_block', TRUE);
   return 'admin/build/block';
 };
 
@@ -642,25 +645,38 @@
   static $blocks = array();
 
   if (!count($blocks)) {
-    $rids = array_keys($user->roles);
-    $placeholders = implode(',', array_fill(0, count($rids), '%d'));
-    $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));
-    while ($block = db_fetch_object($result)) {
-      if (!isset($blocks[$block->region])) {
-        $blocks[$block->region] = array();
-      }
-      // Use the user's block visibility setting, if necessary
-      if ($block->custom != 0) {
-        if ($user->uid && isset($user->block[$block->module][$block->delta])) {
-          $enabled = $user->block[$block->module][$block->delta];
+    $cache_key = $user->uid. '::'. $theme_key;
+    $cache = cache_get($cache_key, 'cache_advcache_block');
+    $enabled_blocks = unserialize($cache->data);
+    if (empty($enabled_blocks)) {
+      $enabled_blocks = array();
+      $rids = array_keys($user->roles);
+      $placeholders = implode(',', array_fill(0, count($rids), '%d'));
+      $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));
+      while ($block = db_fetch_object($result)) {
+        if (!isset($blocks[$block->region])) {
+          $blocks[$block->region] = array();
+        }
+        // Use the user's block visibility setting, if necessary
+        if ($block->custom != 0) {
+          if ($user->uid && isset($user->block[$block->module][$block->delta])) {
+            $enabled = $user->block[$block->module][$block->delta];
+          }
+          else {
+            $enabled = ($block->custom == 1);
+          }
         }
         else {
-          $enabled = ($block->custom == 1);
+          $enabled = TRUE;
+        }
+        if ($enabled) {
+          $enabled_blocks[] = $block;
         }
       }
-      else {
-        $enabled = TRUE;
-      }
+      cache_set($cache_key, 'cache_advcache_block', serialize($enabled_blocks));
+    }
+
+    foreach ($enabled_blocks as $block) {
 
       // Match path if necessary
       if ($block->pages) {
@@ -700,7 +716,7 @@
     if (!isset($block->content)) {
       // Erase the block from the static array - we'll put it back if it has content.
       unset($blocks[$region][$key]);
-      if ($block->enabled && $block->page_match) {
+      if ($block->page_match) {
         // Check the current throttle status and see if block should be displayed
         // based on server load.
         if (!($block->throttle && (module_invoke('throttle', 'status') > 0))) {
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.520.2.12
diff -u -p -r1.520.2.12 comment.module
--- modules/comment/comment.module	7 Nov 2007 08:03:30 -0000	1.520.2.12
+++ modules/comment/comment.module	18 Jul 2008 21:05:06 -0000
@@ -931,6 +931,16 @@ function comment_links($comment, $return
 function comment_render($node, $cid = 0) {
   global $user;
 
+  // If this is an authenticated user who only has one role and cannot admin-
+  // ister comments, look for a cached copy of the comment, or in the case
+  // of $cid = 0, the whole tree of comments.
+  $cache_key = 0;
+  if (!user_access('administer comments') && count($user->roles) === 1 && in_array('authenticated user', $user->roles)) {
+    // Must accommodate pagination
+    $page = isset($_GET['page']) ? $_GET['page'] : '';
+    $cache_key = 'nid-'. $node->nid. '::cid-'. $cid. '::'. $page;
+  }
+
   $output = '';
 
   if (user_access('access comments')) {
@@ -945,6 +955,12 @@ function comment_render($node, $cid = 0)
     $comments_per_page = _comment_get_display_setting('comments_per_page');
 
     if ($cid) {
+      if ($cache_key) {
+        $cache = cache_get($cache_key, 'cache_comment');
+        $comment = unserialize($cache->data);
+      }
+
+      if (!$comment) {
       // Single comment view.
       $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';
       $query_args = array($cid);
@@ -963,11 +979,26 @@ function comment_render($node, $cid = 0)
           $function = $module .'_link_alter';
           $function($node, $links);
         }
+        }
+      }
 
+      if ($comment) {
         $output .= theme('comment_view', $comment, $links);
       }
     }
     else {
+      if ($cache_key) {
+        if ($cache = cache_get($cache_key, 'cache_comment')) {
+          $comments = unserialize($cache->data);
+          $comment_count = count($comments);
+
+          // Get the pager
+          $cache = cache_get($cache_key. '::pager', 'cache_comment');
+          $pager = $cache->data;
+        }
+      }
+
+      if (empty($comments)) {
       // Multiple comment view
       $query_count = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d';
       $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';
@@ -1002,21 +1033,32 @@ function comment_render($node, $cid = 0)
           $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
         }
       }
-
       // Start a form, for use with comment control.
       $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args);
-      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)) {
+        $comment_count = db_num_rows($result);
+      }
+
+
+      if ($comment_count && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
         $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
       }
 
       $divs = 0;
       $last_depth = 0;
       drupal_add_css(drupal_get_path('module', 'comment') .'/comment.css');
+
+      if (empty($comments)) {
+        $comments = array();
       while ($comment = db_fetch_object($result)) {
         $comment = drupal_unpack($comment);
         $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
         $comment->depth = count(explode('.', $comment->thread)) - 1;
+          $comments[] = $comment;
+        }
+        cache_set($cache_key, 'cache_comment', serialize($comments));
+      }
 
+      foreach ($comments as $comment) {
         if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
           if ($comment->depth > $last_depth) {
             $divs++;
@@ -1048,9 +1090,15 @@ function comment_render($node, $cid = 0)
       for ($i = 0; $i < $divs; $i++) {
         $output .= '</div>';
       }
-      $output .= theme('pager', NULL, $comments_per_page, 0);
 
-      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)) {
+      if (empty($pager)) {
+        $pager = theme('pager', NULL, $comments_per_page, 0);
+        cache_set($cache_key. '::pager', 'cache_comment', $pager);
+      }
+
+      $output .= $pager;
+
+      if ($comment_count && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
         $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
       }
     }
@@ -2012,4 +2060,3 @@ function int2vancode($i = 0) {
 function vancode2int($c = '00') {
   return base_convert(substr($c, 1), 36, 10);
 }
-
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.776.2.22
diff -u -p -r1.776.2.22 node.module
--- modules/node/node.module	7 Jan 2008 01:31:26 -0000	1.776.2.22
+++ modules/node/node.module	18 Jul 2008 21:05:07 -0000
@@ -2509,7 +2509,7 @@ function node_page_default($arg = NULL) 
 /**
  * Menu callback; view a single node.
  */
-function node_page_view($node, $cid = NULL) {
+function node_page_view($node, $cid = 0) {
   drupal_set_title(check_plain($node->title));
   return node_show($node, $cid);
 }
? sites/all/modules
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.776.2.28
diff -u -p -r1.776.2.28 node.module
--- modules/node/node.module	7 Jun 2008 00:52:54 -0000	1.776.2.28
+++ modules/node/node.module	18 Jul 2008 21:31:03 -0000
@@ -541,17 +541,31 @@ function node_invoke_nodeapi(&$node, $op
  *   A fully-populated node object.
  */
 function node_load($param = array(), $revision = NULL, $reset = NULL) {
+  global $user;
   static $nodes = array();
 
   if ($reset) {
     $nodes = array();
   }
 
-  $cachable = ($revision == NULL);
+  $cache_id = 0;
   $arguments = array();
   if (is_numeric($param)) {
-    if ($cachable && isset($nodes[$param])) {
-      return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
+    if (module_exists('advcache')) {
+      $cache_id = ($revision == NULL) ? $param. '::'. advcache_array2int($user->roles) : 0;
+    }
+    if ($cache_id > 0) {
+      if (isset($nodes[$param])) {
+        return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
+      }
+      if ($user->uid != 1) {
+        $cache = cache_get($cache_id, 'cache_node');
+        if ($cache) {
+          $cache = unserialize($cache->data);
+          $nodes[$param] = is_object($cache) ? drupal_clone($cache) : $cache;
+          return $nodes[$param];
+        }
+      }
     }
     $cond = 'n.nid = %d';
     $arguments[] = $param;
@@ -589,8 +603,13 @@ function node_load($param = array(), $re
         $node->$key = $value;
       }
     }
-    if ($cachable) {
+    if ($cache_id > 0) {
       $nodes[$node->nid] = is_object($node) ? drupal_clone($node) : $node;
+      if ($user->uid != 1) {
+        if (!in_array($node->type, variable_get('advcache_node_exclude_types', array('poll')))) {
+          cache_set($cache_id, 'cache_node', serialize($nodes[$node->nid]));
+        }
+      }
     }
   }
 
@@ -2025,8 +2044,8 @@ function node_validate($node, $form = ar
   if (isset($node->body) && count(explode(' ', $node->body)) < $type->min_word_count) {
     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)));
   }
-
-  if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {
+  $changed = node_last_changed($node->nid);
+  if (isset($node->nid) && ($changed > $node->changed)) {
     form_set_error('changed', t('This content has been modified by another user, changes cannot be saved.'));
   }
 
? sites/all/modules
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.330.2.17
diff -u -p -r1.330.2.17 taxonomy.module
--- modules/taxonomy/taxonomy.module	6 Jul 2008 00:50:44 -0000	1.330.2.17
+++ modules/taxonomy/taxonomy.module	18 Jul 2008 21:35:10 -0000
@@ -780,12 +780,25 @@ function taxonomy_node_get_terms($nid, $
   static $terms;
 
   if (!isset($terms[$nid][$key])) {
-    $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);
-    $terms[$nid][$key] = array();
-    while ($term = db_fetch_object($result)) {
-      $terms[$nid][$key][$term->$key] = $term;
+    // This caching breaks taxonomy access! The results of db_rewrite_sql will
+    // be cached, meaning the first user to load this node after a cache
+    // refresh will set the permissions for everyone. If you are using a module
+    // that does query rewriting on taxonomy queries, don't use this patch.
+    // If you're not sure whether or not this is the case, don't use this patch!
+    $cache_key = 'node::'. $nid. '::'. $key;
+    if ($cache = cache_get($cache_key, 'cache_taxonomy')) {
+      $terms[$nid][$key] = unserialize($cache->data);
+    }
+    else {
+      $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);
+      $terms[$nid][$key] = array();
+      while ($term = db_fetch_object($result)) {
+        $terms[$nid][$key][$term->$key] = $term;
+      }
+      cache_set($cache_key, 'cache_taxonomy', serialize($terms[$nid][$key]));
     }
   }
+
   return $terms[$nid][$key];
 }
 
@@ -989,7 +1002,14 @@ function taxonomy_get_children($tid, $vi
  */
 function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL) {
   static $children, $parents, $terms;
-
+  if ((0 === $parent) && (-1 === $depth)) {
+    if ($cache = cache_get('tree::'. $vid, 'cache_taxonomy')) {
+      return unserialize($cache->data);
+    }
+    else {
+      $cache_tree = TRUE;
+    }
+  }
   $depth++;
 
   // We cache trees, so it's not CPU-intensive to call get_tree() on a term
@@ -1023,6 +1043,10 @@ function taxonomy_get_tree($vid, $parent
     }
   }
 
+  if ($cache_tree) {
+    cache_set('tree::'. $vid, 'cache_taxonomy', serialize($tree));
+  }
+
   return $tree ? $tree : array();
 }
 
@@ -1146,13 +1170,19 @@ function taxonomy_get_vocabulary($vid) {
   static $vocabularies = array();
 
   if (!array_key_exists($vid, $vocabularies)) {
-    $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);
-    $node_types = array();
-    while ($voc = db_fetch_object($result)) {
-      $node_types[] = $voc->type;
-      unset($voc->type);
-      $voc->nodes = $node_types;
-      $vocabularies[$vid] = $voc;
+    if ($cache = cache_get('vocabulary::'. $vid, 'cache_taxonomy')) {
+      $vocabularies[$vid] = unserialize($cache->data);
+    }
+    else {
+      $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);
+      $node_types = array();
+      while ($voc = db_fetch_object($result)) {
+        $node_types[] = $voc->type;
+        unset($voc->type);
+        $voc->nodes = $node_types;
+        $vocabularies[$vid] = $voc;
+        cache_set('vocabulary::'. $vid, 'cache_taxonomy', serialize($voc));
+      }
     }
   }
 
@@ -1172,7 +1202,13 @@ function taxonomy_get_term($tid) {
   static $terms = array();
 
   if (!isset($terms[$tid])) {
-    $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid));
+    if ($cache = cache_get('term::'. $tid, 'cache_taxonomy')) {
+      $terms[$tid] = unserialize($cache->data);
+    }
+    else {
+      $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid));
+      cache_set('term::'. $tid, 'cache_taxonomy', serialize($terms[$tid]));
+    }
   }
 
   return $terms[$tid];
@@ -1301,8 +1337,8 @@ function taxonomy_render_nodes($result) 
 function taxonomy_nodeapi($node, $op, $arg = 0) {
   switch ($op) {
     case 'load':
-     $output['taxonomy'] = taxonomy_node_get_terms($node->nid);
-     return $output;
+      $output['taxonomy'] = taxonomy_node_get_terms($node->nid);
+      return $output;
     case 'insert':
       taxonomy_node_save($node->nid, $node->taxonomy);
       break;
