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

Diff of /contributions/modules/advcache/DRUPAL-5-6/comment_cache.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/comment/comment.module ./modules/comment/comment.module
2    --- ../drupal/modules/comment/comment.module    2007-11-07 03:03:30.000000000 -0500
3    +++ ./modules/comment/comment.module    2007-12-10 12:33:36.484007596 -0500
4    @@ -931,6 +931,16 @@
5     function comment_render($node, $cid = 0) {
6       global $user;
7    
8    +  // If this is an authenticated user who only has one role and cannot admin-
9    +  // ister comments, look for a cached copy of the comment, or in the case
10    +  // of $cid = 0, the whole tree of comments.
11    +  $cache_key = 0;
12    +  if (!user_access('administer comments') && count($user->roles) === 1 && in_array('authenticated user', $user->roles)) {
13    +    // Must accommodate pagination
14    +    $page = isset($_GET['page']) ? $_GET['page'] : '';
15    +    $cache_key = 'nid-'. $node->nid. '::cid-'. $cid. '::'. $page;
16    +  }
17    +
18       $output = '';
19    
20       if (user_access('access comments')) {
21    @@ -945,6 +955,12 @@
22         $comments_per_page = _comment_get_display_setting('comments_per_page');
23    
24         if ($cid) {
25    +      if ($cache_key) {
26    +        $cache = cache_get($cache_key, 'cache_comment');
27    +        $comment = unserialize($cache->data);
28    +      }
29    +
30    +      if (!$comment) {
31           // Single comment view.
32           $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';
33           $query_args = array($cid);
34    @@ -963,11 +979,26 @@
35               $function = $module .'_link_alter';
36               $function($node, $links);
37             }
38    +        }
39    +      }
40    
41    +      if ($comment) {
42             $output .= theme('comment_view', $comment, $links);
43           }
44         }
45         else {
46    +      if ($cache_key) {
47    +        if ($cache = cache_get($cache_key, 'cache_comment')) {
48    +          $comments = unserialize($cache->data);
49    +          $comment_count = count($comments);
50    +
51    +          // Get the pager
52    +          $cache = cache_get($cache_key. '::pager', 'cache_comment');
53    +          $pager = $cache->data;
54    +        }
55    +      }
56    +
57    +      if (empty($comments)) {
58           // Multiple comment view
59           $query_count = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d';
60           $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';
61    @@ -1002,21 +1033,32 @@
62               $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
63             }
64           }
65    -
66           // Start a form, for use with comment control.
67           $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args);
68    -      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)) {
69    +        $comment_count = db_num_rows($result);
70    +      }
71    +
72    +
73    +      if ($comment_count && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
74             $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
75           }
76    
77           $divs = 0;
78           $last_depth = 0;
79           drupal_add_css(drupal_get_path('module', 'comment') .'/comment.css');
80    +
81    +      if (empty($comments)) {
82    +        $comments = array();
83           while ($comment = db_fetch_object($result)) {
84             $comment = drupal_unpack($comment);
85             $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
86             $comment->depth = count(explode('.', $comment->thread)) - 1;
87    +          $comments[] = $comment;
88    +        }
89    +        cache_set($cache_key, 'cache_comment', serialize($comments));
90    +      }
91    
92    +      foreach ($comments as $comment) {
93             if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
94               if ($comment->depth > $last_depth) {
95                 $divs++;
96    @@ -1048,9 +1090,15 @@
97           for ($i = 0; $i < $divs; $i++) {
98             $output .= '</div>';
99           }
100    -      $output .= theme('pager', NULL, $comments_per_page, 0);
101    
102    -      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)) {
103    +      if (empty($pager)) {
104    +        $pager = theme('pager', NULL, $comments_per_page, 0);
105    +        cache_set($cache_key. '::pager', 'cache_comment', $pager);
106    +      }
107    +
108    +      $output .= $pager;
109    +
110    +      if ($comment_count && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
111             $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
112           }
113         }
114    @@ -2012,4 +2060,3 @@
115     function vancode2int($c = '00') {
116       return base_convert(substr($c, 1), 36, 10);
117     }
118    -
119    diff -Naur ../drupal/modules/node/node.module ./modules/node/node.module
120    --- ../drupal/modules/node/node.module  2007-09-29 19:41:28.000000000 -0400
121    +++ ./modules/node/node.module  2007-12-10 12:33:36.484007596 -0500
122    @@ -2463,7 +2463,7 @@
123     /**
124      * Menu callback; view a single node.
125      */
126    -function node_page_view($node, $cid = NULL) {
127    +function node_page_view($node, $cid = 0) {
128       drupal_set_title(check_plain($node->title));
129       return node_show($node, $cid);
130     }

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

  ViewVC Help
Powered by ViewVC 1.1.3