summaryrefslogtreecommitdiff
path: root/modules/node/node.module
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2006-01-18 21:31:40 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2006-01-18 21:31:40 +0000
commitecd26ac8ae495d785a78f34e3e4170904be7f023 (patch)
tree74ab6705ec1035e735b0369423351d36c4dd6aba /modules/node/node.module
parent9528c30037fce0ab07eac7b054d1b89d16b412b1 (diff)
downloadbrdo-ecd26ac8ae495d785a78f34e3e4170904be7f023.tar.gz
brdo-ecd26ac8ae495d785a78f34e3e4170904be7f023.tar.bz2
- #42277: Make node search indexing more robust against bad nodes and timeouts.
Diffstat (limited to 'modules/node/node.module')
-rw-r--r--modules/node/node.module32
1 files changed, 23 insertions, 9 deletions
diff --git a/modules/node/node.module b/modules/node/node.module
index e8fc08b49..1fdd1e7e5 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -598,12 +598,14 @@ function node_search($op = 'search', $keys = null) {
case 'reset':
variable_del('node_cron_last');
+ variable_del('node_cron_last_nid');
return;
case 'status':
$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 AND moderate = 0'));
- $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 n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d)', $last, $last, $last));
+ $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 n.moderate = 0 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));
return array('remaining' => $remaining, 'total' => $total);
case 'admin':
@@ -2069,28 +2071,40 @@ function node_page() {
}
/**
+ * shutdown function to make sure we always mark the last node processed.
+ */
+function node_update_shutdown() {
+ global $last_change, $last_nid;
+
+ if ($last_change && $last_nid) {
+ variable_set('node_cron_last', $last_change);
+ variable_set('node_cron_last_nid', $last_nid);
+ }
+}
+
+/**
* Implementation of hook_update_index().
*/
function node_update_index() {
+ global $last_change, $last_nid;
+
+ register_shutdown_function('node_update_shutdown');
+
$last = variable_get('node_cron_last', 0);
+ $last_nid = variable_get('node_cron_last_nid', 0);
$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}'))));
- $result = db_query_range('SELECT n.nid, c.last_comment_timestamp FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d) ORDER BY GREATEST(n.created, n.changed, c.last_comment_timestamp) ASC', $last, $last, $last, 0, $limit);
+ $result = db_query_range('SELECT GREATEST(c.last_comment_timestamp, n.changed, n.created) as last_change, n.nid FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 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)) ORDER BY GREATEST(n.created, n.changed, c.last_comment_timestamp) ASC, n.nid ASC', $last, $last_nid, $last, $last, $last, 0, $limit);
while ($node = db_fetch_object($result)) {
- $last_comment = $node->last_comment_timestamp;
+ $last_change = $node->last_change;
+ $last_nid = $node->nid;
$node = node_load($node->nid);
- // We update this variable per node in case cron times out, or if the node
- // cannot be indexed (PHP nodes which call drupal_goto, for example).
- // In rare cases this can mean a node is only partially indexed, but the
- // chances of this happening are very small.
- variable_set('node_cron_last', max($last_comment, $node->changed, $node->created));
-
// Get node output (filtered and with module-specific fields).
if (node_hook($node, 'view')) {
node_invoke($node, 'view', false, false);