You are here

function content_update_6004 in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 6.3 content.install \content_update_6004()

Index the 'nid' column on data tables to optimize node deletion. Large tables might deserve a multipass update.

File

./content.install, line 391

Code

function content_update_6004(&$sandbox) {
  if ($abort = content_check_update()) {
    return $abort;
  }
  $ret = array();

  // Do nothing if the indexes were already created by D5's content_update_1009.
  if (variable_get('content_update_1009', FALSE)) {
    return $ret;
  }

  // Gather list of tables.
  if (!isset($sandbox['tables'])) {
    drupal_load('module', 'content');
    $sandbox['tables'] = array();
    $result = db_query('SELECT * FROM {' . content_instance_tablename() . '} nfi ' . ' LEFT JOIN {' . content_field_tablename() . '} nf ON nf.field_name = nfi.field_name');
    while ($field = db_fetch_array($result)) {
      if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) {
        $table = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD);
      }
      else {
        $table = _content_tablename($field['type_name'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
      }
      $sandbox['tables'][$table] = $table;
    }
    $sandbox['count'] = count($sandbox['tables']);
  }

  // One pass : add index on one table.
  if ($table = array_shift($sandbox['tables'])) {
    db_add_index($ret, $table, 'nid', array(
      'nid',
    ));
  }
  if ($sandbox['count']) {
    $ret['#finished'] = 1 - count($sandbox['tables']) / $sandbox['count'];
  }
  variable_set('content_schema_version', 6004);
  return $ret;
}