? css
? favicon.ico
? files
? i148849.patch
? img
? index.html
? test
? modules/node/node.install
? sites/default/settings.php
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.549
diff -u -p -r1.549 comment.module
--- modules/comment/comment.module	4 Jun 2007 15:56:31 -0000	1.549
+++ modules/comment/comment.module	4 Jun 2007 21:25:26 -0000
@@ -290,8 +290,7 @@ function comment_block($op = 'list', $de
 /**
  * Find a number of recent comments. This is done in two steps.
  *   1. Find the n (specified by $number) nodes that have the most recent
- *      comments.  This is done by querying node_comment_statistics which has
- *      an index on last_comment_timestamp, and is thus a fast query.
+ *      comments.
  *   2. Loading the information from the comments table based on the nids found
  *      in step 1.
  *
@@ -303,8 +302,8 @@ function comment_block($op = 'list', $de
 function comment_get_recent($number = 10) {
   // Select the $number nodes (visible to the current user) with the most
   // recent comments. This is efficient due to the index on
-  // last_comment_timestamp.
-  $result = db_query_range(db_rewrite_sql("SELECT nc.nid FROM {node_comment_statistics} nc WHERE nc.comment_count > 0 ORDER BY nc.last_comment_timestamp DESC", 'nc'), 0, $number);
+  // last_activity_timestamp.
+  $result = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.comment_count > 0 ORDER BY n.last_activity_timestamp DESC", 'nc'), 0, $number);
 
   $nids = array();
   while ($row = db_fetch_object($result)) {
@@ -460,7 +459,7 @@ function comment_form_alter(&$form, $for
 function comment_nodeapi(&$node, $op, $arg = 0) {
   switch ($op) {
     case 'load':
-      return db_fetch_array(db_query("SELECT last_comment_timestamp, last_comment_name, comment_count FROM {node_comment_statistics} WHERE nid = %d", $node->nid));
+      return db_fetch_array(db_query("SELECT last_activity_timestamp, lau.name AS last_activity_name, comment_count FROM {node} INNER JOIN {users} lau ON lau.uid= n.last_activity_user WHERE nid = %d", $node->nid));
       break;
 
     case 'prepare':
@@ -469,13 +468,8 @@ function comment_nodeapi(&$node, $op, $a
       }
       break;
 
-    case 'insert':
-      db_query('INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) VALUES (%d, %d, NULL, %d, 0)', $node->nid, $node->created, $node->uid);
-      break;
-
     case 'delete':
       db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid);
-      db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid);
       break;
 
     case 'update index':
@@ -487,7 +481,7 @@ function comment_nodeapi(&$node, $op, $a
       return $text;
 
     case 'search result':
-      $comments = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $node->nid));
+      $comments = db_result(db_query('SELECT comment_count FROM {node} WHERE nid = %d', $node->nid));
       return format_plural($comments, '1 comment', '@count comments');
 
     case 'rss item':
@@ -506,7 +500,7 @@ function comment_nodeapi(&$node, $op, $a
 function comment_user($type, $edit, &$user, $category = NULL) {
   if ($type == 'delete') {
     db_query('UPDATE {comments} SET uid = 0 WHERE uid = %d', $user->uid);
-    db_query('UPDATE {node_comment_statistics} SET last_comment_uid = 0 WHERE last_comment_uid = %d', $user->uid);
+    db_query('UPDATE {node} SET last_activity_uid = 0 WHERE last_activity_uid = %d', $user->uid);
   }
 }
 
@@ -1354,7 +1348,7 @@ function comment_num_all($nid) {
   static $cache;
 
   if (!isset($cache[$nid])) {
-    $cache[$nid] = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $nid));
+    $cache[$nid] = db_result(db_query('SELECT comment_count FROM {node} WHERE nid = %d', $nid));
   }
   return $cache[$nid];
 }
@@ -2006,10 +2000,9 @@ function _comment_get_display_setting($s
  * Updates the comment statistics for a given node. This should be called any
  * time a comment is added, deleted, or updated.
  *
- * The following fields are contained in the node_comment_statistics table.
- * - last_comment_timestamp: the timestamp of the last comment for this node or the node create stamp if no comments exist for the node.
- * - last_comment_name: the name of the anonymous poster for the last comment
- * - last_comment_uid: the uid of the poster for the last comment for this node or the node authors uid if no comments exists for the node.
+ * The following fields are contained in the node table.
+ * - last_activity_timestamp: the timestamp of the last comment for this node or the node create stamp if no comments exist for the node.
+ * - last_activity_uid: the uid of the poster for the last comment for this node or the node author's uid if no comments exists for the node.
  * - comment_count: the total number of approved/published comments on this node.
  */
 function _comment_update_node_statistics($nid) {
@@ -2017,14 +2010,13 @@ function _comment_update_node_statistics
 
   // comments exist
   if ($count > 0) {
-    $last_reply = db_fetch_object(db_query_range('SELECT cid, name, timestamp, uid FROM {comments} WHERE nid = %d AND status = %d ORDER BY cid DESC', $nid, COMMENT_PUBLISHED, 0, 1));
-    db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, $last_reply->timestamp, $last_reply->uid ? '' : $last_reply->name, $last_reply->uid, $nid);
+    $last_reply = db_fetch_object(db_query_range('SELECT cid, timestamp, uid FROM {comments} WHERE nid = %d AND status = %d ORDER BY cid DESC', $nid, COMMENT_PUBLISHED, 0, 1));
+    db_query("UPDATE {node} SET comment_count = %d, last_activity_timestamp = %d, last_activity_uid = %d WHERE nid = %d", $count, $last_reply->timestamp, $last_reply->uid, $nid);
   }
 
   // no comments
   else {
-    $node = db_fetch_object(db_query("SELECT uid, created FROM {node} WHERE nid = %d", $nid));
-    db_query("UPDATE {node_comment_statistics} SET comment_count = 0, last_comment_timestamp = %d, last_comment_name = '', last_comment_uid = %d WHERE nid = %d", $node->created, $node->uid, $nid);
+    db_query("UPDATE {node} SET comment_count = 0, last_activity_timestamp = created, last_activity_uid = uid WHERE nid = %d", $nid);
   }
 }
 
Index: modules/comment/comment.schema
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.schema,v
retrieving revision 1.1
diff -u -p -r1.1 comment.schema
--- modules/comment/comment.schema	25 May 2007 12:46:44 -0000	1.1
+++ modules/comment/comment.schema	4 Jun 2007 21:25:26 -0000
@@ -28,18 +28,6 @@ function comment_schema() {
     'primary key' => array('cid'),
   );
 
-  $schema['node_comment_statistics'] = array(
-    'fields' => array(
-      'nid'                    => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
-      'last_comment_timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'last_comment_name'      => array('type' => 'varchar', 'length' => 60, 'not null' => FALSE),
-      'last_comment_uid'       => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'comment_count'          => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)
-    ),
-    'indexes' => array('node_comment_timestamp' => array('last_comment_timestamp')),
-    'primary key' => array('nid'),
-  );
-
   return $schema;
 }
 
Index: modules/forum/forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v
retrieving revision 1.402
diff -u -p -r1.402 forum.module
--- modules/forum/forum.module	4 Jun 2007 15:56:32 -0000	1.402
+++ modules/forum/forum.module	4 Jun 2007 21:25:26 -0000
@@ -286,7 +286,7 @@ function forum_block($op = 'list', $delt
         switch ($delta) {
           case 0:
             $title = t('Active forum topics');
-            $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND n.type = 'forum' ORDER BY l.last_comment_timestamp DESC");
+            $sql = db_rewrite_sql("SELECT n.nid, n.title, n.comment_count, n.last_activity_timestamp FROM {node} n WHERE n.status = 1 AND n.type = 'forum' ORDER BY n.last_activity_timestamp DESC");
             $result = db_query_range($sql, 0, variable_get('forum_block_num_0', '5'));
             if (db_num_rows($result)) {
               $content = node_title_list($result);
@@ -295,7 +295,7 @@ function forum_block($op = 'list', $delt
 
           case 1:
             $title = t('New forum topics');
-            $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.type = 'forum' AND n.status = 1 ORDER BY n.nid DESC");
+            $sql = db_rewrite_sql("SELECT n.nid, n.title, n.comment_count FROM {node} n WHERE n.type = 'forum' AND n.status = 1 ORDER BY n.nid DESC");
             $result = db_query_range($sql, 0, variable_get('forum_block_num_1', '5'));
             if (db_num_rows($result)) {
               $content = node_title_list($result);
@@ -765,7 +765,7 @@ function forum_get_forums($tid = 0) {
 
     $counts = array();
 
-    $sql = "SELECT r.tid, COUNT(n.nid) AS topic_count, SUM(l.comment_count) AS comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.status = 1 AND n.type = 'forum' GROUP BY r.tid";
+    $sql = "SELECT r.tid, COUNT(n.nid) AS topic_count, SUM(n.comment_count) AS comment_count FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.status = 1 AND n.type = 'forum' GROUP BY r.tid";
     $sql = db_rewrite_sql($sql);
     $_counts = db_query($sql);
     while ($count = db_fetch_object($_counts)) {
@@ -787,18 +787,15 @@ function forum_get_forums($tid = 0) {
       $forum->num_posts = 0;
     }
 
-    // This query does not use full ANSI syntax since MySQL 3.x does not support
-    // table1 INNER JOIN table2 INNER JOIN table3 ON table2_criteria ON table3_criteria
-    // used to join node_comment_statistics to users.
-    $sql = "SELECT ncs.last_comment_timestamp, IF (ncs.last_comment_uid != 0, u2.name, ncs.last_comment_name) AS last_comment_name, ncs.last_comment_uid FROM {node} n INNER JOIN {users} u1 ON n.uid = u1.uid INNER JOIN {term_node} tn ON n.nid = tn.nid INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {users} u2 ON ncs.last_comment_uid=u2.uid WHERE n.status = 1 AND n.type='forum' AND tn.tid = %d ORDER BY ncs.last_comment_timestamp DESC";
+    $sql = "SELECT n.last_activity_timestamp, lau.name AS last_activity_name, n.last_activity_uid FROM {node} n INNER JOIN {users} lau ON n.last_activity_uid = lau.uid INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE n.status = 1 AND n.type='forum' AND tn.tid = %d ORDER BY n.last_activity_timestamp DESC";
     $sql = db_rewrite_sql($sql);
     $topic = db_fetch_object(db_query_range($sql, $forum->tid, 0, 1));
 
     $last_post = new stdClass();
-    if (!empty($topic->last_comment_timestamp)) {
-      $last_post->timestamp = $topic->last_comment_timestamp;
-      $last_post->name = $topic->last_comment_name;
-      $last_post->uid = $topic->last_comment_uid;
+    if (!empty($topic->last_activity_timestamp)) {
+      $last_post->timestamp = $topic->last_activity_timestamp;
+      $last_post->name = $topic->last_activity_name;
+      $last_post->uid = $topic->last_activity_uid;
     }
     $forum->last_post = $last_post;
 
@@ -824,9 +821,9 @@ function forum_get_topics($tid, $sortby,
   $forum_topic_list_header = array(
     array('data' => '&nbsp;', 'field' => NULL),
     array('data' => t('Topic'), 'field' => 'n.title'),
-    array('data' => t('Replies'), 'field' => 'l.comment_count'),
+    array('data' => t('Replies'), 'field' => 'n.comment_count'),
     array('data' => t('Created'), 'field' => 'n.created'),
-    array('data' => t('Last reply'), 'field' => 'l.last_comment_timestamp'),
+    array('data' => t('Last reply'), 'field' => 'n.last_activity_timestamp'),
   );
 
   $order = _forum_get_topic_order($sortby);
@@ -838,7 +835,7 @@ function forum_get_topics($tid, $sortby,
 
   $term = taxonomy_get_term($tid);
 
-  $sql = db_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid != 0, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f, {node} n WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = %d AND n.uid = u.uid AND n.vid = f.vid");
+  $sql = db_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, n.last_activity_timestamp, lau.name AS last_activity_name, n.last_activity_uid, n.comment_count AS num_comments FROM {node} n INNER JOIN {users} lau ON n.last_activity_uid = lau.uid INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {forum} f ON n.vid = f.vid WHERE n.status = 1 AND r.tid = %d");
   $sql .= tablesort_sql($forum_topic_list_header, 'n.sticky DESC,');
   $sql .= ', n.created DESC';  // Always add a secondary sort order so that the news forum topics are on top.
 
@@ -866,9 +863,9 @@ function forum_get_topics($tid, $sortby,
 
     if ($topic->num_comments > 0) {
       $last_reply = new stdClass();
-      $last_reply->timestamp = $topic->last_comment_timestamp;
-      $last_reply->name = $topic->last_comment_name;
-      $last_reply->uid = $topic->last_comment_uid;
+      $last_reply->timestamp = $topic->last_activity_timestamp;
+      $last_reply->name = $topic->last_activity_name;
+      $last_reply->uid = $topic->last_activity_uid;
       $topic->last_reply = $last_reply;
     }
     $topics[] = $topic;
@@ -1110,7 +1107,7 @@ function theme_forum_topic_navigation($n
   $output = '';
 
   // get previous and next topic
-  $sql = "SELECT n.nid, n.title, n.sticky, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 AND n.type = 'forum' ORDER BY n.sticky DESC, ". _forum_get_topic_order_sql(variable_get('forum_order', 1));
+  $sql = "SELECT n.nid, n.title, n.sticky, n.comment_count, n.last_activity_timestamp FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 AND n.type = 'forum' ORDER BY n.sticky DESC, ". _forum_get_topic_order_sql(variable_get('forum_order', 1));
   $result = db_query(db_rewrite_sql($sql), isset($node->tid) ? $node->tid : 0);
 
   $stop = 0;
@@ -1167,16 +1164,16 @@ function _forum_user_last_visit($nid) {
 function _forum_get_topic_order($sortby) {
   switch ($sortby) {
     case 1:
-      return array('field' => 'l.last_comment_timestamp', 'sort' => 'desc');
+      return array('field' => 'n.last_activity_timestamp', 'sort' => 'desc');
       break;
     case 2:
-      return array('field' => 'l.last_comment_timestamp', 'sort' => 'asc');
+      return array('field' => 'n.last_activity_timestamp', 'sort' => 'asc');
       break;
     case 3:
-      return array('field' => 'l.comment_count', 'sort' => 'desc');
+      return array('field' => 'n.comment_count', 'sort' => 'desc');
       break;
     case 4:
-      return array('field' => 'l.comment_count', 'sort' => 'asc');
+      return array('field' => 'n.comment_count', 'sort' => 'asc');
       break;
   }
 }
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.827
diff -u -p -r1.827 node.module
--- modules/node/node.module	4 Jun 2007 16:46:48 -0000	1.827
+++ modules/node/node.module	4 Jun 2007 21:25:26 -0000
@@ -88,7 +88,7 @@ function node_cron() {
  * Gather a listing of links to nodes.
  *
  * @param $result
- *   A DB result object from a query to fetch node objects. If your query joins the <code>node_comment_statistics</code> table so that the <code>comment_count</code> field is available, a title attribute will be added to show the number of comments.
+ *   A DB result object from a query to fetch node objects. A title attribute is added to show the number of comments.
  * @param $title
  *   A heading for the resulting list.
  *
@@ -97,7 +97,7 @@ function node_cron() {
  */
 function node_title_list($result, $title = NULL) {
   while ($node = db_fetch_object($result)) {
-    $items[] = l($node->title, 'node/'. $node->nid, !empty($node->comment_count) ? array('title' => format_plural($node->comment_count, '1 comment', '@count comments')) : array());
+    $items[] = l($node->title, 'node/'. $node->nid, array('title' => format_plural($node->comment_count, '1 comment', '@count comments')));
   }
 
   return theme('node_list', $items, $title);
@@ -666,12 +666,14 @@ function node_save(&$node) {
                     'title' => $node->title, 'type' => $node->type, 'uid' => $node->uid,
                     'status' => $node->status, 'language' => $node->language, 'created' => $node->created,
                     'changed' => $node->changed, 'comment' => $node->comment,
-                    'promote' => $node->promote, 'sticky' => $node->sticky);
+                    'promote' => $node->promote, 'sticky' => $node->sticky,
+                    'last_activity_timestamp' => $node->changed);
   $node_table_types = array('nid' => '%d', 'vid' => '%d',
                     'title' => "'%s'", 'type' => "'%s'", 'uid' => '%d',
                     'status' => '%d', 'language' => "'%s'",'created' => '%d',
                     'changed' => '%d', 'comment' => '%d',
-                    'promote' => '%d', 'sticky' => '%d');
+                    'promote' => '%d', 'sticky' => '%d',
+                    'last_activity_timestamp' => '%d');
 
   //Generate the node table query and the
   //the node_revisions table query
@@ -871,7 +873,7 @@ function node_search($op = 'search', $ke
       $last = variable_get('node_cron_last', 0);
       $last_nid = variable_get('node_cron_last_nid', 0);
       $total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1'));
-      $remaining = db_result(db_query('SELECT COUNT(*) FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND ((GREATEST(n.created, n.changed, c.last_comment_timestamp) = %d AND n.nid > %d ) OR (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d))', $last, $last_nid, $last, $last, $last));
+      $remaining = db_result(db_query('SELECT COUNT(*) FROM {node} n WHERE n.status = 1 AND ((n.last_activity_timestamp = %d AND n.nid > %d ) OR (n.last_activity_timestamp > %d))', $last, $last_nid, $last));
       return array('remaining' => $remaining, 'total' => $total);
 
     case 'admin':
@@ -929,8 +931,8 @@ function node_search($op = 'search', $ke
       $ranking = array();
       $arguments2 = array();
       $join2 = '';
-      // Used to avoid joining on node_comment_statistics twice
-      $stats_join = FALSE;
+      // Used to avoid joining on node twice
+      $node_join = FALSE;
       $total = 0;
       if ($weight = (int)variable_get('node_rank_relevance', 5)) {
         // Average relevance values hover around 0.15
@@ -940,11 +942,11 @@ function node_search($op = 'search', $ke
       }
       if ($weight = (int)variable_get('node_rank_recent', 5)) {
         // Exponential decay with half-life of 6 months, starting at last indexed node
-        $ranking[] = '%d * POW(2, (GREATEST(n.created, n.changed, c.last_comment_timestamp) - %d) * 6.43e-8)';
+        $ranking[] = '%d * POW(2, (n.last_activity_timestamp - %d) * 6.43e-8)';
         $arguments2[] = $weight;
         $arguments2[] = (int)variable_get('node_cron_last', 0);
-        $join2 .= ' INNER JOIN {node} n ON n.nid = i.sid LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
-        $stats_join = TRUE;
+        $join2 .= ' INNER JOIN {node} n ON n.nid = i.sid';
+        $node_join = TRUE;
         $total += $weight;
       }
       if (module_exists('comment') && $weight = (int)variable_get('node_rank_comments', 5)) {
@@ -953,8 +955,9 @@ function node_search($op = 'search', $ke
         $ranking[] = '%d * (2.0 - 2.0 / (1.0 + c.comment_count * %f))';
         $arguments2[] = $weight;
         $arguments2[] = $scale;
-        if (!$stats_join) {
-          $join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
+        if (!$node_join) {
+          $join2 .= ' INNER JOIN {node} n ON n.nid = i.sid';
+          $node_join = TRUE;
         }
         $total += $weight;
       }
@@ -965,7 +968,10 @@ function node_search($op = 'search', $ke
         $ranking[] = '%d * (2.0 - 2.0 / (1.0 + nc.totalcount * %f))';
         $arguments2[] = $weight;
         $arguments2[] = $scale;
-        $join2 .= ' LEFT JOIN {node_counter} nc ON nc.nid = i.sid';
+        if (!$node_join) {
+          $join2 .= ' INNER JOIN {node} n ON n.nid = i.sid';
+          $node_join = TRUE;
+        }
         $total += $weight;
       }
       $select2 = (count($ranking) ? implode(' + ', $ranking) : 'i.relevance') .' AS score';
@@ -2535,10 +2541,10 @@ function node_update_index() {
   $limit = (int)variable_get('search_cron_limit', 100);
 
   // Store the maximum possible comments per thread (used for ranking by reply count)
-  variable_set('node_cron_comments_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'))));
-  variable_set('node_cron_views_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(totalcount) FROM {node_counter}'))));
+  variable_set('node_cron_comments_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(comment_count) FROM {node}'))));
+  variable_set('node_cron_views_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(totalcount) FROM {node}'))));
 
-  $result = db_query_range('SELECT GREATEST(IF(c.last_comment_timestamp IS NULL, 0, c.last_comment_timestamp), n.changed) as last_change, n.nid FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND ((GREATEST(n.changed, c.last_comment_timestamp) = %d AND n.nid > %d) OR (n.changed > %d OR c.last_comment_timestamp > %d)) ORDER BY GREATEST(n.changed, c.last_comment_timestamp) ASC, n.nid ASC', $last, $last_nid, $last, $last, $last, 0, $limit);
+  $result = db_query_range('SELECT n.last_activity_timestamp as last_change, n.nid FROM {node} n WHERE n.status = 1 AND ((n.last_activity_timestamp = %d AND n.nid > %d) OR n.last_activity_timestamp > %d) ORDER BY n.last_activity_timestamp ASC, n.nid ASC', $last, $last_nid, $last, 0, $limit);
 
   while ($node = db_fetch_object($result)) {
     $last_change = $node->last_change;
Index: modules/node/node.schema
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.schema,v
retrieving revision 1.1
diff -u -p -r1.1 node.schema
--- modules/node/node.schema	25 May 2007 12:46:45 -0000	1.1
+++ modules/node/node.schema	4 Jun 2007 21:25:26 -0000
@@ -4,31 +4,38 @@
 function node_schema() {
   $schema['node'] = array(
     'fields' => array(
-      'nid'      => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
-      'vid'      => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
-      'type'     => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
-      'language' => array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''),
-      'title'    => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
-      'uid'      => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'status'   => array('type' => 'int', 'not null' => TRUE, 'default' => 1),
-      'created'  => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'changed'  => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'comment'  => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'promote'  => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'moderate' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'sticky'   => array('type' => 'int', 'not null' => TRUE, 'default' => 0)
+      'nid'                     => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
+      'vid'                     => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+      'type'                    => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
+      'language'                => array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''),
+      'title'                   => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
+      'uid'                     => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'status'                  => array('type' => 'int', 'not null' => TRUE, 'default' => 1),
+      'created'                 => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'changed'                 => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'comment'                 => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'promote'                 => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'moderate'                => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'sticky'                  => array('type' => 'int', 'not null' => TRUE, 'default' => 0)
+      'last_activity_timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'last_activity_uid'       => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'comment_count'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)
+      'views_total'             => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'big'),
+      'views_today'             => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'medium'),
+      'last_viewed_timestamp'   => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)
     ),
     'indexes' => array(
-      'nid'                 => array('nid'),
-      'node_changed'        => array('changed'),
-      'node_created'        => array('created'),
-      'node_moderate'       => array('moderate'),
-      'node_promote_status' => array('promote', 'status'),
-      'node_status_type'    => array('status', 'type', 'nid'),
-      'node_title_type'     => array('title', array('type', 4)),
-      'node_type'           => array(array('type', 4)),
-      'status'              => array('status'),
-      'uid'                 => array('uid')
+      'nid'                    => array('nid'),
+      'node_changed'           => array('changed'),
+      'node_created'           => array('created'),
+      'node_moderate'          => array('moderate'),
+      'node_promote_status'    => array('promote', 'status'),
+      'node_status_type'       => array('status', 'type', 'nid'),
+      'node_title_type'        => array('title', array('type', 4)),
+      'node_type'              => array(array('type', 4)),
+      'status'                 => array('status'),
+      'uid'                    => array('uid')
+      'node_comment_timestamp' => array('last_comment_timestamp'),
     ),
     'unique keys' => array(
       'nid_vid' => array('nid', 'vid'),
@@ -53,16 +60,6 @@ function node_schema() {
     ),
   );
 
-  $schema['node_counter'] = array(
-    'fields' => array(
-      'nid'        => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
-      'totalcount' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'big'),
-      'daycount'   => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'medium'),
-      'timestamp'  => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)
-    ),
-    'primary key' => array('nid'),
-  );
-
   $schema['node_revisions'] = array(
     'fields' => array(
       'nid'       => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
Index: modules/search/search.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/search/search.module,v
retrieving revision 1.224
diff -u -p -r1.224 search.module
--- modules/search/search.module	4 Jun 2007 07:22:22 -0000	1.224
+++ modules/search/search.module	4 Jun 2007 21:25:27 -0000
@@ -848,7 +848,7 @@ function _search_parse_query(&$word, &$s
  *
  * @param $join2
  *   (optional) Inserted into the JOIN par of the second SQL query.
- *   For example "INNER JOIN {node_comment_statistics} n ON n.nid = i.sid"
+ *   For example "INNER JOIN {node} n ON n.nid = i.sid".
  *
  * @param $arguments2
  *   (optional) Extra SQL arguments belonging to the second query parameter.
Index: modules/tracker/tracker.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/tracker/tracker.module,v
retrieving revision 1.148
diff -u -p -r1.148 tracker.module
--- modules/tracker/tracker.module	16 May 2007 13:45:16 -0000	1.148
+++ modules/tracker/tracker.module	4 Jun 2007 21:25:27 -0000
@@ -83,14 +83,14 @@ function tracker_page($uid = 0) {
 
   // TODO: These queries are very expensive, see http://drupal.org/node/105639
   if ($uid) {
-    $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d) ORDER BY last_updated DESC';
+    $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, n.last_activity_timestamp AS last_updated, n.comment_count FROM {node} n INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d) ORDER BY last_updated DESC';
     $sql = db_rewrite_sql($sql);
     $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d)';
     $sql_count = db_rewrite_sql($sql_count);
     $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $uid, $uid);
   }
   else {
-    $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 ORDER BY last_updated DESC';
+    $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, n.last_activity_timestamp AS last_updated, n.comment_count FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 ORDER BY last_updated DESC';
     $sql = db_rewrite_sql($sql);
     $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1';
     $sql_count = db_rewrite_sql($sql_count);
