Browse Source

Added delayed constraint checking to available bulk loader speed-up options

Lacey Sanderson 12 years ago
parent
commit
11e0888acb

+ 17 - 8
tripal_bulk_loader/tripal_bulk_loader.admin.inc

@@ -64,18 +64,26 @@ function tripal_bulk_loader_configuration_form($form_state = NULL) {
     '#default_value' => variable_get('tripal_bulk_loader_prepare', TRUE),
   );
 
+  $form['speed']['disable_triggers'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Delay Constraint Checking during loading job.'),
+    '#description' => t('This delays the constraint checking until the end of the
+    loading proccess.'),
+    '#default_value' => variable_get('tripal_bulk_loader_disable_triggers', TRUE),
+  );
+
   $form['speed']['transactions'] = array(
     '#type' => 'radios',
     '#title' => t('Transaction Rollback when an error is encountered'),
     '#options' => array(
-      'all' => t('<b>Rollback the last constant set.</b> This is the fastest option. If '
-        .'you added more then one constant set then the successfully loaded constant '
-        .'sets will not be rolled back. However, once an error is encountered no further '
-        .'constant sets will be loaded either.'),
-      'row' => t('<b>Only Rollback the last line of the input file.</b> This option '
-        .'may allow you to restart the job after fixing the error (manual intervention '
-        .'needed) but is also slower are requires additional memory.'),
-      'none' => t('<b>Do not use transactions</b> This is not recommended.')
+      'all' => t('Rollback the last constant set.'
+        .'<div class="description"If you added more then one constant set then the
+        successfully loaded constant sets will not be rolled back. However, once an error
+        is encountered no further constant sets will be loaded either.</div>'),
+      'row' => t('Only Rollback the last line of the input file.'
+        .'<div class="description">This option may allow you to restart the job after
+        fixing the error (manual intervention needed).</div>'),
+      'none' => t('Do not use transactions<div class="description">This is not recommended.</div>')
     ),
     '#default_value' => variable_get('tripal_bulk_loader_transactions','row')
   );
@@ -94,6 +102,7 @@ function tripal_bulk_loader_configuration_form($form_state = NULL) {
 function tripal_bulk_loader_configuration_form_submit($form, $form_state) {
 
   variable_set('tripal_bulk_loader_prepare', $form_state['values']['prepare']);
+  variable_set('tripal_bulk_loader_disable_triggers', $form_state['values']['disable_triggers']);
   variable_set('tripal_bulk_loader_transactions',$form_state['values']['transactions']);
 
 }

+ 15 - 3
tripal_bulk_loader/tripal_bulk_loader.loader.inc

@@ -135,13 +135,14 @@ function tripal_bulk_loader_load_data($nid) {
   $default_data = array();
   $field2column = array();
   $record2priority = array();
+  $tables = array();
 
   foreach ($node->template->template_array as $priority => $record_array) {
     if (!is_array($record_array)) {
       continue;
     }
 
-    //watchdog('T_bulk_loader','1)'.$record_array['record_id']." => \n<pre>".print_r($record_array,TRUE).'</pre>', array(), WATCHDOG_NOTICE);
+    $tables[$record_array['table']] = $record_array['table'];
 
     foreach ($record_array['fields'] as $field_index => $field_array) {
 
@@ -257,14 +258,23 @@ function tripal_bulk_loader_load_data($nid) {
         break;
       case "all":
         tripal_db_start_transaction();
+        $transactions = TRUE;
         $savepoint = "";
         break;
       case "row":
         tripal_db_start_transaction();
+        $transactions = TRUE;
         $savepoint = "last_row_complete";
         break;
     }
 
+    // Disable triggers
+    $triggers_disabled = FALSE;
+    if ($transactions AND variable_get('tripal_bulk_loader_disable_triggers', TRUE)) {
+      $triggers_disabled = TRUE;
+      chado_query("SET CONSTRAINTS ALL DEFERRED");
+    }
+
     while (!feof($file_handle)) {
 
       // Clear variables
@@ -305,7 +315,7 @@ function tripal_bulk_loader_load_data($nid) {
         $status = process_data_array_for_line($priority, $data, $default_data, $field2column, $record2priority, $line, $nid, $num_lines, $group_index);
         if (!$status ) {
           // Encountered an error
-          if (variable_get('tripal_bulk_loader_transactions','row') != 'none') {
+          if ($transactions) {
             tripal_db_rollback_transaction($savepoint);
           }
           $failed = TRUE;
@@ -333,11 +343,13 @@ function tripal_bulk_loader_load_data($nid) {
     } //end of foreach line of file
 
     // END Transaction
-    if (variable_get('tripal_bulk_loader_transactions','row') != 'none') {
+    if ($transactions) {
+      // end the transaction
       tripal_db_commit_transaction();
     }
 
     if ($failed) {
+      $loaded_without_errors = FALSE;
       break;
     }
 

+ 1 - 1
tripal_core/tripal_core.api.inc

@@ -1916,7 +1916,7 @@ function tripal_db_start_transaction() {
 }
 
 /**
- *
+ * Set a savepoint to roll the current transaction back to if an error is encountered
  */
 function tripal_db_set_savepoint_transaction($savepoint, $release = FALSE) {
   // Postgresql requires a savepoint of the same name to be unset before re-use