? modules/node/node.install
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.547
diff -u -p -r1.547 comment.module
--- modules/comment/comment.module 29 May 2007 06:27:37 -0000 1.547
+++ modules/comment/comment.module 3 Jun 2007 01:44:30 -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.
*
@@ -304,7 +303,7 @@ 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);
+ $result = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.comment_count > 0 ORDER BY n.last_comment_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_comment_timestamp, last_comment_name, comment_count FROM {node} 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_comment_uid = 0 WHERE last_comment_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];
}
@@ -2005,10 +1999,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) {
@@ -2016,14 +2009,14 @@ 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 = %d, last_activity_uid = %d WHERE nid = %d", $node->created, $node->uid, $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 3 Jun 2007 01:44:30 -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/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.823
diff -u -p -r1.823 node.module
--- modules/node/node.module 1 Jun 2007 11:17:44 -0000 1.823
+++ modules/node/node.module 3 Jun 2007 01:44:31 -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 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. 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';
@@ -2530,10 +2536,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 3 Jun 2007 01:44:31 -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),