Index: comment.module =================================================================== RCS file: /var/cvsroot/events/modules/comment/comment.module,v retrieving revision 1.1.1.2 retrieving revision 1.10 diff -r1.1.1.2 -r1.10 800c801,811 < --- > > // Clear cache_comment of all keys for this nid > $cache_hash_key = 'nid-' . $edit['nid'] . '::hash'; > if ($cache = cache_get($cache_hash_key, 'cache_comment')) { > $cache_hash = $cache->data; > cache_clear_all($cache_hash_key, 'cache_comment'); > foreach($cache_hash as $cache_key) { > cache_clear_all($cache_key, 'cache_comment'); > } > } > 946a958,968 > // 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 . '::' . $mode . '-' . $order . '-' . $comments_per_page . '-' . $page; > $cache_hash_key = 'nid-' . $node->nid . '::hash'; > } > 948,964c970,983 < // 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); < if (!user_access('administer comments')) { < $query .= ' AND c.status = %d'; < $query_args[] = COMMENT_PUBLISHED; < } < < $result = db_query($query, $query_args); < < if ($comment = db_fetch_object($result)) { < $comment->name = $comment->uid ? $comment->registered_name : $comment->name; < $links = module_invoke_all('link', 'comment', $comment, 1); < < foreach (module_implements('link_alter') as $module) { < $function = $module .'_link_alter'; < $function($node, $links); --- > if ($cache_key) { > $cache = cache_get($cache_key, 'cache_comment'); > // hack. ruman. memcache. > // $comment = unserialize($cache->data); > $comment = $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); > if (!user_access('administer comments')) { > $query .= ' AND c.status = %d'; > $query_args[] = COMMENT_PUBLISHED; 965a985,986 > > $result = db_query($query, $query_args); 966a988,1003 > if ($comment = db_fetch_object($result)) { > $comment->name = $comment->uid ? $comment->registered_name : $comment->name; > $links = module_invoke_all('link', 'comment', $comment, 1); > > foreach (module_implements('link_alter') as $module) { > $function = $module .'_link_alter'; > $function($node, $links); > } > > // cache the single comment > if ($cache_key) { > cache_set($cache_key, 'cache_comment', $comment); > } > } > } > if ($comment) { 971,987c1008,1017 < // 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'; < < $query_args = array($nid); < if (!user_access('administer comments')) { < $query .= ' AND c.status = %d'; < $query_count .= ' AND status = %d'; < $query_args[] = COMMENT_PUBLISHED; < } < < if ($order == COMMENT_ORDER_NEWEST_FIRST) { < if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) { < $query .= ' ORDER BY c.timestamp DESC'; < } < else { < $query .= ' ORDER BY c.thread DESC'; --- > if ($cache_key) { > if ($cache = cache_get($cache_key, 'cache_comment')) { > // hack. ruman. memcache. > // $comments = unserialize($cache->data); > $comments = $cache->data; > $comment_count = count($comments); > > // Get the pager > $cache = cache_get($cache_key. '::pager', 'cache_comment'); > $pager = $cache->data; 990,994d1019 < else if ($order == COMMENT_ORDER_OLDEST_FIRST) { < if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) { < $query .= ' ORDER BY c.timestamp'; < } < else { 996,1002c1021,1039 < /* < ** See comment above. Analysis learns that this doesn't cost < ** too much. It scales much much better than having the whole < ** comment structure. < */ < < $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))'; --- > 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'; > > $query_args = array($nid); > if (!user_access('administer comments')) { > $query .= ' AND c.status = %d'; > $query_count .= ' AND status = %d'; > $query_args[] = COMMENT_PUBLISHED; > } > > if ($order == COMMENT_ORDER_NEWEST_FIRST) { > if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) { > $query .= ' ORDER BY c.timestamp DESC'; > } > else { > $query .= ' ORDER BY c.thread DESC'; > } 1003a1041,1058 > else if ($order == COMMENT_ORDER_OLDEST_FIRST) { > if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) { > $query .= ' ORDER BY c.timestamp'; > } > else { > > /* > ** See comment above. Analysis learns that this doesn't cost > ** too much. It scales much much better than having the whole > ** comment structure. > */ > > $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); > $comment_count = db_num_rows($result); 1005,1008c1060,1061 < < // 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)) { --- > > if ($comment_count && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) { 1011c1064 < --- > 1015,1018c1068,1093 < 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; --- > > 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; > } > > if ($cache_key) { > // get the cache_hash. add the cache key to the array > if ($cache = cache_get($cache_hash_key, 'cache_comment')) { > $cache_hash = $cache->data; > $cache_hash[] = $cache_key; > } > else { > $cache_hash = array($cache_key); > } > cache_set($cache_hash_key, 'cache_comment', $cache_hash); > > // hack. ruman. memcache. > // cache_set($cache_key, 'cache_comment', serialize($comments)); > cache_set($cache_key, 'cache_comment', $comments); > } > } 1019a1095 > foreach ($comments as $comment) { 1034c1110 < --- > 1051d1126 < $output .= theme('pager', NULL, $comments_per_page, 0); 1053c1128,1148 < 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); > > if ($cache_key && $pager) { > // get the cache_hash. add the pager cache key to the array > if ($cache = cache_get($cache_hash_key, 'cache_comment')) { > $cache_hash = $cache->data; > $cache_hash[] = $cache_key. '::pager'; > } > else { > $cache_hash = array($cache_key. '::pager'); > } > cache_set($cache_hash_key, 'cache_comment', $cache_hash); > > 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)) { 1111c1206,1207 < // Clear the cache so an anonymous user sees that his comment was deleted. --- > > // Clear the cache so an anonymous user sees that his comment was deleted. 1113a1210,1219 > // Clear cache_comment of all keys for this nid > $cache_hash_key = 'nid-' . $comment->nid . '::hash'; > if ($cache = cache_get($cache_hash_key, 'cache_comment')) { > $cache_hash = $cache->data; > cache_clear_all($cache_hash_key, 'cache_comment'); > foreach($cache_hash as $cache_key) { > cache_clear_all($cache_key, 'cache_comment'); > } > } > 1227a1334,1342 > // Clear cache_comment of all keys for this nid > $cache_hash_key = 'nid-' . $comment->nid . '::hash'; > if ($cache = cache_get($cache_hash_key, 'cache_comment')) { > $cache_hash = $cache->data; > cache_clear_all($cache_hash_key, 'cache_comment'); > foreach($cache_hash as $cache_key) { > cache_clear_all($cache_key, 'cache_comment'); > } > } 1232a1348 > 1305a1422,1430 > // Clear cache_comment of all keys for this nid > $cache_hash_key = 'nid-' . $comment->nid . '::hash'; > if ($cache = cache_get($cache_hash_key, 'cache_comment')) { > $cache_hash = $cache->data; > cache_clear_all($cache_hash_key, 'cache_comment'); > foreach($cache_hash as $cache_key) { > cache_clear_all($cache_key, 'cache_comment'); > } > }