diff -urNp notify-head/notify.module notify-efficiency-patch/notify.module --- notify-head/notify.module 2006-08-11 14:24:47.000000000 -0700 +++ notify-efficiency-patch/notify.module 2006-11-18 08:34:35.000000000 -0800 @@ -306,27 +306,31 @@ function _notify_send() { 'INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND u.status = 1 AND n.attempts <= %d', variable_get('notify_attempts', 5)); + // Fetch all new nodes and load them to get proper body, etc. + $nresult = db_query('SELECT n.nid FROM {node} n WHERE (n.status = 1 OR n.moderate = 1) ' . + 'AND n.created > %d ORDER BY n.created', $period); + $nodes = array(); + while ($node = db_fetch_object($nresult)) { + $nodes[$node->nid] = node_load($node->nid); + } + + // Fetch new comments + $cresult = db_query('SELECT c.nid, c.cid, c.subject, c.pid, c.name FROM {comments} c ' . + 'WHERE c.status = %d AND c.timestamp > %d ' . + 'ORDER BY c.nid, c.timestamp', COMMENT_PUBLISHED, $period); + $comments = array(); + while ($comment = db_fetch_object($cresult)) { + $comments[$comment->nid][] = $comment; + // If we don't already have the node, fetch it. + if (!isset($nodes[$comment->nid])) { + $nodes[$comment->nid] = node_load($comment->nid); + } + } + while ($user = db_fetch_object($uresult)) { // Switch current user to this account to use node_access functions, etc. _notify_switch_user($user->uid); - // Fetch all new nodes and 'load' it to get proper body, etc. - $nresult = db_query(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE (n.status = 1 OR n.moderate = 1) ' . - 'AND n.created > %d ORDER BY n.created'), $period); - $nodes = array(); - while ($node = db_fetch_object($nresult)) { - $nodes[$node->nid] = node_load($node->nid); - } - - // Fetch new comments - $cresult = db_query(db_rewrite_sql('SELECT c.nid, c.cid, c.subject, c.pid, u.name FROM {comments} c ' . - 'INNER JOIN {users} u ON u.uid = c.uid WHERE c.status = %d AND c.timestamp > %d ' . - 'ORDER BY c.nid, c.timestamp', 'c'), COMMENT_PUBLISHED, $period); - $comments = array(); - while ($comment = db_fetch_object($cresult)) { - $comments[$comment->nid][] = $comment; - } - $node_body = ''; $comment_body = ''; @@ -374,10 +378,6 @@ function _notify_send() { $nid_old = 0; foreach ($comments as $nid => $comment) { if ($nid != $nid_old) { - // If we don't already have the node, fetch it. - if (!isset($nodes[$nid])) { - $nodes[$nid] = node_load($nid); - } // Don't show comments if we're not allowed to view this node. if (!node_access('view', $nodes[$nid], $user->uid)) {