Index: modules/tracker/tracker.module =================================================================== RCS file: /cvs/drupal/drupal/modules/tracker/tracker.module,v retrieving revision 1.143 diff -u -p -r1.143 tracker.module --- modules/tracker/tracker.module 10 Jan 2007 15:17:51 -0000 1.143 +++ modules/tracker/tracker.module 11 May 2007 23:08:26 -0000 @@ -76,45 +76,60 @@ function tracker_page($uid = 0) { // Add CSS drupal_add_css(drupal_get_path('module', 'tracker') .'/tracker.css', 'module', 'all', FALSE); - // TODO: These queries are very expensive, see http://drupal.org/node/105639 + // Note: we get the nodes first, and then the user names in a separate + // query because doing a join in a single query is slow for large databases. 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, 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 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, 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 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); $result = pager_query($sql, 25, 0, $sql_count); } - $rows = array(); + $nodes = $uids = array(); while ($node = db_fetch_object($result)) { - // Determine the number of comments: - $comments = 0; - if (module_exists('comment') && $node->comment_count) { - $comments = $node->comment_count; - - if ($new = comment_num_new($node->nid)) { - $comments .= '
'; - $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", NULL, NULL, 'new'); + $nodes[] = $node; + $uids[] = $node->uid; + } + if ($nodes) { + $names = array(); + $uids = array_unique($uids); + $result = db_query("SELECT u.uid, u.name FROM {users} u WHERE u.uid IN (". implode(', ', $uids) .")"); + while ($account = db_fetch_object($result)) { + $names[$account->uid] = $account->name; + } + + $rows = array(); + foreach ($nodes as $node) { + $node->name = $names[$node->uid]; + // Determine the number of comments: + $comments = 0; + if (module_exists('comment') && $node->comment_count) { + $comments = $node->comment_count; + + if ($new = comment_num_new($node->nid)) { + $comments .= '
'; + $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", NULL, NULL, 'new'); + } } + + $rows[] = array( + node_get_types('name', $node->type), + l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)), + theme('username', $node), + array('class' => 'replies', 'data' => $comments), + t('!time ago', array('!time' => format_interval(time() - $node->last_updated))) + ); } - - $rows[] = array( - node_get_types('name', $node->type), - l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)), - theme('username', $node), - array('class' => 'replies', 'data' => $comments), - t('!time ago', array('!time' => format_interval(time() - $node->last_updated))) - ); } - - if (!$rows) { + else{ $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '5')); }