Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.471
diff -u -F^f -r1.471 comment.module
--- modules/comment/comment.module 6 Aug 2006 23:00:42 -0000 1.471
+++ modules/comment/comment.module 7 Aug 2006 02:42:49 -0000
@@ -198,7 +198,7 @@ function comment_link($type, $node = NUL
// Main page: display the number of comments that have been posted.
if (user_access('access comments')) {
- $all = comment_num_all($node->nid);
+ $all = $node->comment_count;
$new = comment_num_new($node->nid);
if ($all) {
@@ -308,23 +308,14 @@ function comment_form_alter($form_id, &$
*/
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));
- break;
-
case 'prepare':
if (!isset($node->comment)) {
$node->comment = variable_get("comment_$node->type", COMMENT_NODE_READ_WRITE);
}
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':
@@ -336,8 +327,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));
- return format_plural($comments, '1 comment', '%count comments');
+ return format_plural($node->comment_count, '1 comment', '%count comments');
case 'rss item':
if ($node->comment != COMMENT_NODE_DISABLED) {
@@ -372,7 +362,7 @@ function comment_user($type, $edit, &$us
}
elseif ($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_comment_uid = 0 WHERE last_comment_uid = %d', $user->uid);
}
}
@@ -1170,15 +1160,6 @@ function _comment_load($cid) {
return db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $cid));
}
-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));
- }
- return $cache[$nid];
-}
-
function comment_num_replies($pid) {
static $cache;
@@ -1783,7 +1764,6 @@ 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.
@@ -1795,10 +1775,10 @@ 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);
+ db_query("UPDATE {node} 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);
}
- // no comments
+ // no comments. probably deleting the only comment
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);
Index: modules/forum/forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v
retrieving revision 1.344
diff -u -F^f -r1.344 forum.module
--- modules/forum/forum.module 6 Aug 2006 23:00:42 -0000 1.344
+++ modules/forum/forum.module 7 Aug 2006 02:42:50 -0000
@@ -264,7 +264,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 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 FROM {node} n WHERE n.status = 1 AND n.type = 'forum' ORDER BY n.last_comment_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);
@@ -273,7 +273,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);
@@ -713,7 +713,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, $forum->tid);
while ($count = db_fetch_object($_counts)) {
@@ -738,7 +738,7 @@ function forum_get_forums($tid = 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 tn.tid = %d ORDER BY ncs.last_comment_timestamp DESC";
+ $sql = "SELECT n.last_comment_timestamp, IF (n.last_comment_uid != 0, u2.name, n.last_comment_name) AS last_comment_name, n.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 {users} u2 ON n.last_comment_uid=u2.uid WHERE n.status = 1 AND tn.tid = %d ORDER BY n.last_comment_timestamp DESC";
$sql = db_rewrite_sql($sql);
$topic = db_fetch_object(db_query_range($sql, $forum->tid, 0, 1));
@@ -770,9 +770,9 @@ function forum_get_topics($tid, $sortby,
$forum_topic_list_header = array(
array('data' => ' '),
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_comment_timestamp'),
);
$order = _forum_get_topic_order($sortby);
@@ -784,10 +784,10 @@ 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_comment_timestamp, IF(n.last_comment_uid != 0, cu.name, n.last_comment_name) AS last_comment_name, n.last_comment_uid, n.comment_count AS num_comments FROM {users} cu, {term_node} r, {users} u, {forum} f, {node} n WHERE n.status = 1 AND n.last_comment_uid = cu.uid AND n.nid = n.nid AND n.nid = r.nid AND r.tid = %d AND n.uid = u.uid AND n.vid = f.vid");
$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.
-
+
$sql_count = db_rewrite_sql("SELECT COUNT(n.nid) 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'");
$result = pager_query($sql, $forum_per_page, 0, $sql_count, $tid);
@@ -1067,7 +1067,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_comment_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), $node->tid);
$stop = 0;
@@ -1124,16 +1124,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_comment_timestamp', 'sort' => 'desc');
break;
case 2:
- return array('field' => 'l.last_comment_timestamp', 'sort' => 'asc');
+ return array('field' => 'n.last_comment_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.667
diff -u -F^f -r1.667 node.module
--- modules/node/node.module 6 Aug 2006 23:00:42 -0000 1.667
+++ modules/node/node.module 7 Aug 2006 02:42:52 -0000
@@ -63,7 +63,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 node_comment_statistics table so that the comment_count 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.
* @param $title
* A heading for the resulting list.
*
@@ -488,7 +488,7 @@ function node_load($param = array(), $re
$node = db_fetch_object(db_query('SELECT n.nid, r.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE '. $cond, $arguments));
}
else {
- $node = db_fetch_object(db_query('SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond, $arguments));
+ $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, n.last_comment_timestamp, n.last_comment_uid, n.last_comment_name, n.comment_count, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE '. $cond), $arguments));
}
if ($node->nid) {
@@ -528,7 +528,7 @@ function node_save(&$node) {
$node->is_new = TRUE;
$node->nid = db_next_id('{node}_nid');
- $node->vid = db_next_id('{node_revisions}_vid');;
+ $node->vid = db_next_id('{node_revisions}_vid');
}
else {
// We need to ensure that all node fields are filled.
@@ -574,6 +574,10 @@ function node_save(&$node) {
//Generate the node table query and the
//the node_revisions table query
if ($node->is_new) {
+ // populate comment fields with defaults which ease queries such as in tracker.module
+ $node_table_types['last_comment_uid'] = $node->uid;
+ $node_table_types['last_comment_timestamp'] = $node->created;
+
$node_query = 'INSERT INTO {node} ('. implode(', ', array_keys($node_table_types)) .') VALUES ('. implode(', ', $node_table_types) .')';
$revisions_query = 'INSERT INTO {node_revisions} ('. implode(', ', array_keys($revisions_table_types)) .') VALUES ('. implode(', ', $revisions_table_types) .')';
}
@@ -738,7 +742,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 ((GREATEST(n.created, n.changed, n.last_comment_timestamp) = %d AND n.nid > %d ) OR (n.created > %d OR n.changed > %d OR n.last_comment_timestamp > %d))', $last, $last_nid, $last, $last, $last));
return array('remaining' => $remaining, 'total' => $total);
case 'admin':
@@ -805,21 +809,18 @@ 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, (GREATEST(n.created, n.changed, n.last_comment_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';
+ $join2 .= ' INNER JOIN {node} n ON n.nid = i.sid';
$stats_join = TRUE;
}
if (module_exist('comment') && $weight = (int)variable_get('node_rank_comments', 5)) {
// Inverse law that maps the highest reply count on the site to 1 and 0 to 0.
$scale = variable_get('node_cron_comments_scale', 0.0);
- $ranking[] = '%d * (2.0 - 2.0 / (1.0 + c.comment_count * %f))';
+ $ranking[] = '%d * (2.0 - 2.0 / (1.0 + n.comment_count * %f))';
$arguments2[] = $weight;
$arguments2[] = $scale;
- if (!$stats_join) {
- $join2 .= ' LEFT JOIN {node_comment_statistics} c ON c.nid = i.sid';
- }
}
if (module_exist('statistics') && variable_get('statistics_count_content_views', 0) &&
$weight = (int)variable_get('node_rank_views', 5)) {
@@ -2318,10 +2319,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_comments_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(comment_count) FROM {node} WHERE status = 1'))));
variable_set('node_cron_views_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(totalcount) FROM {node_counter}'))));
- $result = db_query_range('SELECT GREATEST(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 GREATEST(n.last_comment_timestamp, n.changed) as last_change, n.nid FROM {node} n WHERE n.status = 1 AND ((GREATEST(n.changed, n.last_comment_timestamp) = %d AND n.nid > %d) OR (n.changed > %d OR n.last_comment_timestamp > %d)) ORDER BY GREATEST(n.changed, n.last_comment_timestamp) ASC, n.nid ASC', $last, $last_nid, $last, $last, $last, 0, $limit);
while ($node = db_fetch_object($result)) {
$last_change = $node->last_change;
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.5
diff -u -F^f -r1.5 system.install
--- modules/system/system.install 6 Aug 2006 23:00:42 -0000 1.5
+++ modules/system/system.install 7 Aug 2006 02:42:55 -0000
@@ -3025,3 +3025,49 @@ function system_update_188() {
return $ret;
}
+
+function system_update_189() {
+ // Move comment statistics to node table to reduce JOINs
+
+ // multi-part update. see http://drupal.org/node/51220
+ if (!isset($_SESSION['update_188_nid'])) {
+ // These variables keep track of our progress
+ $_SESSION['update_188_nid'] = 0;
+ $_SESSION['update_188_max'] = db_query('SELECT MAX(nid) FROM {node}');
+
+ switch ($GLOBALS['db_type']) {
+ case 'mysql':
+ case 'mysqli':
+ db_query("ALTER TABLE {node} ADD last_comment_timestamp int(11) default 0 NOT NULL");
+ db_query("ALTER TABLE {node} ADD last_comment_uid int(11) default 0 NOT NULL");
+ db_query("ALTER TABLE {node} ADD last_comment_name varchar(255)");
+ db_query("ALTER TABLE {node} ADD comment_count int(11) default 0 NOT NULL");
+ break;
+ case 'pgsql':
+ db_add_column($ret, 'node', 'last_comment_timestamp', 'int', array('default' => 0, 'not null' => TRUE));
+ db_add_column($ret, 'node', 'last_comment_uid', 'int', array('default' => 0, 'not null' => TRUE));
+ db_add_column($ret, 'node', 'last_comment_name', 'varchar(255)', array('default' => NULL, 'not null' => FALSE));
+ db_add_column($ret, 'node', 'comment_count', 'int', array('default' => 0, 'not null' => TRUE));
+ break;
+ }
+ }
+
+ $sql = "SELECT * FROM {node_comment_statistics} ORDER BY nid ASC";
+ $result = db_query_range($sql, $_SESSION['update_188_nid'], 50);
+ while ($row = db_fetch_object($result)) {
+ db_query("UPDATE {node} SET last_comment_timestamp=%d, last_comment_uid=%d, last_comment_name='%s', comment_count=%d WHERE nid = %d", $row->last_comment_timestamp, $row->last_comment_uid, $row->last_comment_name, $row->comment_count, $row->nid);
+ $_SESSION['update_188_nid'] = $row->nid;
+ }
+
+ // See if we are done
+ if ($_SESSION['update_188_nid'] < $_SESSION['update_188_max']) {
+ // Not done yet. Return the progress.
+ return array('#finished' => $_SESSION['update_188_nid'] / $_SESSION['update_188_max']);
+ }
+ else {
+ // Done. Clean up and indicate we're finished.
+ unset($_SESSION['update_188_nid'], $_SESSION['update_188_max']);
+ // db_query('DROP TABLE {node_comment_statistics}');
+ return array('#finished' => 1);
+ }
+}
Index: modules/tracker/tracker.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/tracker/tracker.module,v
retrieving revision 1.132
diff -u -F^f -r1.132 tracker.module
--- modules/tracker/tracker.module 6 Aug 2006 23:00:42 -0000 1.132
+++ modules/tracker/tracker.module 7 Aug 2006 02:42:55 -0000
@@ -83,14 +83,14 @@ function tracker_track_user() {
*/
function tracker_page($uid = 0) {
if ($uid) {
- $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, l.last_comment_timestamp AS last_post, 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_post DESC';
+ $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.created, n.last_comment_timestamp) AS last_post, 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_post 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, l.last_comment_timestamp AS last_post, 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_post DESC';
+ $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.created, n.last_comment_timestamp) AS last_post, n.comment_count FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 ORDER BY last_post 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);