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

Diff of /contributions/modules/advcache/DRUPAL-5-10/comment_cache.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

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

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

  ViewVC Help
Powered by ViewVC 1.1.3