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);
 }
