Skip to content
Snippets Groups Projects
Commit 5be1de31 authored by David Rothstein's avatar David Rothstein
Browse files

Issue #2174551 by David_Rothstein, mikeytown2, hswong3i: Taxonomy_update_7011 runs out of memory.

parent 7b794acf
No related branches found
No related tags found
No related merge requests found
Drupal 7.27, xxxx-xx-xx (development version) Drupal 7.27, xxxx-xx-xx (development version)
----------------------- -----------------------
- Fixed up a bug in the Taxonomy module update function introduced in Drupal
7.26 that caused memory and CPU problems on sites with very large numbers of
unpublished nodes.
Drupal 7.26, 2014-01-15 Drupal 7.26, 2014-01-15
---------------------- ----------------------
......
...@@ -903,13 +903,34 @@ function taxonomy_update_7010() { ...@@ -903,13 +903,34 @@ function taxonomy_update_7010() {
/** /**
* Drop unpublished nodes from the index. * Drop unpublished nodes from the index.
*/ */
function taxonomy_update_7011() { function taxonomy_update_7011(&$sandbox) {
$nids = db_query('SELECT nid from {node} WHERE status = :status', array(':status' => NODE_NOT_PUBLISHED))->fetchCol(); // Initialize information needed by the batch update system.
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['max'] = db_query('SELECT COUNT(DISTINCT n.nid) FROM {node} n INNER JOIN {taxonomy_index} t ON n.nid = t.nid WHERE n.status = :status', array(':status' => NODE_NOT_PUBLISHED))->fetchField();
// If there's no data, don't bother with the extra work.
if (empty($sandbox['max'])) {
return;
}
}
// Process records in groups of 5000.
$limit = 5000;
$nids = db_query_range('SELECT DISTINCT n.nid FROM {node} n INNER JOIN {taxonomy_index} t ON n.nid = t.nid WHERE n.status = :status', 0, $limit, array(':status' => NODE_NOT_PUBLISHED))->fetchCol();
if (!empty($nids)) { if (!empty($nids)) {
db_delete('taxonomy_index') db_delete('taxonomy_index')
->condition('nid', $nids) ->condition('nid', $nids)
->execute(); ->execute();
} }
// Update our progress information for the batch update.
$sandbox['progress'] += $limit;
// Indicate our current progress to the batch update system, if the update is
// not yet complete.
if ($sandbox['progress'] < $sandbox['max']) {
$sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
}
} }
/** /**
......
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