diff -Naur ../drupal/modules/comment/comment.module ./modules/comment/comment.module --- ../drupal/modules/comment/comment.module 2007-11-07 03:03:30.000000000 -0500 +++ ./modules/comment/comment.module 2007-12-10 12:33:36.484007596 -0500 @@ -931,6 +931,16 @@ 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 @@ $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 = $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 @@ $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 @@ for ($i = 0; $i < $divs; $i++) { $output .= ''; } - $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 vancode2int($c = '00') { return base_convert(substr($c, 1), 36, 10); } - diff -Naur ../drupal/modules/node/node.module ./modules/node/node.module --- ../drupal/modules/node/node.module 2007-09-29 19:41:28.000000000 -0400 +++ ./modules/node/node.module 2007-12-10 12:33:36.484007596 -0500 @@ -2463,7 +2463,7 @@ /** * 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); }