diff --git a/apachesolr.index.inc b/apachesolr.index.inc index 2e9a541..6721b26 100644 --- a/apachesolr.index.inc +++ b/apachesolr.index.inc @@ -326,31 +326,19 @@ function apachesolr_add_tags_to_document($document, $text) { /** * hook_cron() helper to try to make {apachesolr_search_node} consistent with {node}. - * TODO: this function is never used */ function apachesolr_cron_check_node_table() { // Check for unpublished content that wasn't deleted from the index. $query = db_select('apachesolr_search_node', 'asn') ->fields('n', array('nid', 'status')) - ->condition('asn.status', 'n.status', '<>'); + ->where('asn.status <> n.status'); $query->innerJoin('node', 'n', 'n.nid = asn.nid'); - $result = $query->execute(); + $nodes = $query->execute()->fetchAllAssoc('nid'); - $node_lists = array(); - $nodes = array(); // Update or delete at most this many in each Solr query. $limit = variable_get('apachesolr_cron_mass_limit', 500); - foreach ($result as $node) { - $nodes[$node->nid] = $node; - if (count($nodes) == $limit) { - $node_lists[] = $nodes; - $nodes = array(); - } - } - // Any remaning ones if the limit is not reached. - if (count($nodes)) { - $node_lists[] = $nodes; - } + $node_lists = array_chunk($nodes, $limit, TRUE); + foreach ($node_lists as $nodes) { watchdog('Apache Solr', 'On cron running apachesolr_nodeapi_mass_update() on nids @nids', array('@nids' => implode(',', array_keys($nodes))), WATCHDOG_WARNING); if (!apachesolr_nodeapi_mass_update($nodes)) { @@ -363,21 +351,9 @@ function apachesolr_cron_check_node_table() { ->fields('asn', array('nid')) ->isNull('n.nid'); $query->leftJoin('node', 'n', 'n.nid = asn.nid'); - $result = $query->execute(); - - $node_lists = array(); - $nodes = array(); - foreach ($result as $node) { - $nodes[$node->nid] = $node; - if (count($nodes) == $limit) { - $node_lists[] = $nodes; - $nodes = array(); - } - } - // Any remaning ones if the limit is not reached. - if (count($nodes)) { - $node_lists[] = $nodes; - } + $nodes = $query->execute()->fetchAllAssoc('nid'); + $node_lists = array_chunk($nodes, $limit, TRUE); + foreach ($node_lists as $nodes) { watchdog('Apache Solr', 'On cron running apachesolr_nodeapi_mass_delete() on nids @nids', array('@nids' => implode(',', array_keys($nodes))), WATCHDOG_WARNING); if (!apachesolr_nodeapi_mass_delete($nodes)) {