From 7ad36e3f59b9e50e7da68dff87a254eac4084977 Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Thu, 4 Nov 2004 20:17:07 +0000 Subject: [PATCH] - Modifed patch by ccourtne: made the tracker module take advantage of the node_comment_statistics table. Improves performance of the tracker page by facter 10 because it eliminates up to 20 SQL queries. --- modules/tracker.module | 10 +++++----- modules/tracker/tracker.module | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/tracker.module b/modules/tracker.module index c0a1098bed63..f18b43f66959 100644 --- a/modules/tracker.module +++ b/modules/tracker.module @@ -67,17 +67,17 @@ function tracker_page($uid = 0) { $output .= ''; if ($uid) { - $result = pager_query('SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_post FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d) GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d)', $uid, $uid); + $result = pager_query('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 '. node_access_join_sql() .' 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 = 0 WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d) ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid AND c.status = 0 WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d)', $uid, $uid); } else { - $result = pager_query('SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_post FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND '. node_access_where_sql() .' GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() .' WHERE n.status = 1 AND '. node_access_where_sql()); + $result = pager_query('SELECT 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 '. node_access_join_sql() .' INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND '. node_access_where_sql() .' ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(n.nid) FROM {node} n '. node_access_join_sql() .' WHERE n.status = 1 AND '. node_access_where_sql()); } - + while ($node = db_fetch_object($result)) { // Determine the number of comments: $comments = 0; - if (module_exist('comment') && $all = comment_num_all($node->nid)) { - $comments = $all; + if (module_exist('comment') && $node->comment_count) { + $comments = $node->comment_count; if ($new = comment_num_new($node->nid)) { $comments .= '<br />'; diff --git a/modules/tracker/tracker.module b/modules/tracker/tracker.module index c0a1098bed63..f18b43f66959 100644 --- a/modules/tracker/tracker.module +++ b/modules/tracker/tracker.module @@ -67,17 +67,17 @@ function tracker_page($uid = 0) { $output .= ''; if ($uid) { - $result = pager_query('SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_post FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d) GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d)', $uid, $uid); + $result = pager_query('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 '. node_access_join_sql() .' 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 = 0 WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d) ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid AND c.status = 0 WHERE n.status = 1 AND '. node_access_where_sql() .' AND (n.uid = %d OR c.uid = %d)', $uid, $uid); } else { - $result = pager_query('SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_post FROM {node} n '. node_access_join_sql() .' LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND '. node_access_where_sql() .' GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '. node_access_join_sql() .' WHERE n.status = 1 AND '. node_access_where_sql()); + $result = pager_query('SELECT 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 '. node_access_join_sql() .' INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND '. node_access_where_sql() .' ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(n.nid) FROM {node} n '. node_access_join_sql() .' WHERE n.status = 1 AND '. node_access_where_sql()); } - + while ($node = db_fetch_object($result)) { // Determine the number of comments: $comments = 0; - if (module_exist('comment') && $all = comment_num_all($node->nid)) { - $comments = $all; + if (module_exist('comment') && $node->comment_count) { + $comments = $node->comment_count; if ($new = comment_num_new($node->nid)) { $comments .= '<br />'; -- GitLab