diff --git includes/admin.batch_confirm.inc includes/admin.batch_confirm.inc index 4361fc3..5e2a552 100644 --- includes/admin.batch_confirm.inc +++ includes/admin.batch_confirm.inc @@ -10,7 +10,7 @@ * Run a SQL query in batch for each row in the {project_issues} table. * * This function will find the range of all rows in the {project_issues} table - * and run a query against that table incerementally, 100 rows at a time. This + * and run a query against that table incerementally, 500 rows at a time. This * function is intended to be used with batch_set(). * * @param $sql @@ -25,39 +25,28 @@ * An array containing information about batch progress. $context['sandbox'] * contains the following keys which will be populated after this function * has been called: - * 'min' The minimum value, or starting point. * 'max' The maximum value, or end point. * 'current' The nid of the last row that has been updated. - * 'finished' Will contain a percentage of total rows processed, and will - * be set to 1 when all rows have been processed. */ function _project_issue_batch_update($sql, $base_arguments, &$context = array()) { - $last_nid = 0; - $first_nid = 0; - if (!isset($context['sandbox']['min'])) { - // Avoid COUNT(*) like hell. + if (!isset($context['sandbox']['current'])) { $context['sandbox']['max'] = db_result(db_query('SELECT MAX(nid) FROM {project_issues}')); - // We will use > so use - 1 when choosing the smallest nid. - $context['sandbox']['min'] = db_result(db_query('SELECT MIN(nid) - 1 FROM {project_issues}')); - $context['sandbox']['current'] = $context['sandbox']['min']; + $context['sandbox']['current'] = 0; } + + $limit = 500; + + // Add range of rows to process to query arguments. $arguments = $base_arguments; - // MySQL does not support LIMIT & IN/ALL/ANY/SOME subquery so we do the hard - // work ourselves: find 100 nids and record the first and the last. - $results = db_query_range('SELECT nid FROM {project_issues} WHERE nid > %d ORDER BY nid ASC', $context['sandbox']['current'], 0, 100); - while ($node = db_fetch_object($results)) { - if (!isset($first_nid)) { - $first_nid = $node->nid; - } - $last_nid = $node->nid; - } - $arguments[] = $first_nid; + $last_nid = $context['sandbox']['current'] + $limit; + $arguments[] = $context['sandbox']['current']; $arguments[] = $last_nid; + db_query($sql, $arguments); - // Note that we do not count exactly as there can be holes. That's still - // better than running COUNT() on large datasets. + + // Check to see if finished, report progress and update $context['sandbox']['current']. if ($last_nid < $context['sandbox']['max']) { - $context['finished'] = ($last_nid - $context['sandbox']['min']) / ($context['sandbox']['max'] - $context['sandbox']['min']); + $context['finished'] = $last_nid / $context['sandbox']['max']; $context['sandbox']['current'] = $last_nid; } else {