Skip to content
Snippets Groups Projects
Commit 7ad36e3f authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Modifed patch by ccourtne: made the tracker module take advantage of the...

- 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.
parent b6eee48c
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -67,17 +67,17 @@ function tracker_page($uid = 0) { ...@@ -67,17 +67,17 @@ function tracker_page($uid = 0) {
$output .= ''; $output .= '';
if ($uid) { 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 { 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)) { while ($node = db_fetch_object($result)) {
// Determine the number of comments: // Determine the number of comments:
$comments = 0; $comments = 0;
if (module_exist('comment') && $all = comment_num_all($node->nid)) { if (module_exist('comment') && $node->comment_count) {
$comments = $all; $comments = $node->comment_count;
if ($new = comment_num_new($node->nid)) { if ($new = comment_num_new($node->nid)) {
$comments .= '<br />'; $comments .= '<br />';
......
...@@ -67,17 +67,17 @@ function tracker_page($uid = 0) { ...@@ -67,17 +67,17 @@ function tracker_page($uid = 0) {
$output .= ''; $output .= '';
if ($uid) { 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 { 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)) { while ($node = db_fetch_object($result)) {
// Determine the number of comments: // Determine the number of comments:
$comments = 0; $comments = 0;
if (module_exist('comment') && $all = comment_num_all($node->nid)) { if (module_exist('comment') && $node->comment_count) {
$comments = $all; $comments = $node->comment_count;
if ($new = comment_num_new($node->nid)) { if ($new = comment_num_new($node->nid)) {
$comments .= '<br />'; $comments .= '<br />';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment