From f9bc08541ffc4c7c3b6a47d1b96d57163094be4e Mon Sep 17 00:00:00 2001
From: Andreas Romeyke <art1@andreas-romeyke.de>
Date: Mon, 2 Aug 2021 15:59:36 +0200
Subject: [PATCH] - use explicite transaction to increase performance - fixed
 multiple connect/disconnect calls to db in inner loop

---
 perl/exit_strategy.pl | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/perl/exit_strategy.pl b/perl/exit_strategy.pl
index 2dc0d2f..7119fa6 100644
--- a/perl/exit_strategy.pl
+++ b/perl/exit_strategy.pl
@@ -205,6 +205,7 @@ SQL_LOCAT_PLAN
       (SELECT id FROM aip WHERE aip.ie_id=\$1 AND aip.version=\$2), \$3, \$4
     );
 SQL_DC_PLAN
+  $dbh->begin_work;
   my $sth_aip_plan = $dbh->prepare($sql_aip_plan);
   my $sth_ie_plan = $dbh->prepare($sql_ie_plan);
   my $sth_file_plan = $dbh->prepare($sql_file_plan);
@@ -226,6 +227,7 @@ SQL_DC_PLAN
     $dcvalue=~tr/'/"/;
     $sth_dc_plan->execute($ieid, $ieversion, $dckey, $dcvalue)  or die "sql problem detected", $dbh->errstr;
   }
+  $dbh->commit;
   return 1;
 }
 
@@ -530,20 +532,19 @@ my $cnt_unsorted_files = searching_ie_files(\@dirs, $tmp_ies_unsorted_file);
 my $fh_unsorted_IEs = $tmp_ies_unsorted_file->openr();
 my $count = 0;
 my $progressbar = Time::Progress->new(min => 0, max => $cnt_unsorted_files, smoothing => 1);
+my $dbh = DBI->connect("dbi:SQLite:dbname=$db_filename", "", "", {
+    RaiseError     => 1,
+    sqlite_unicode => 1,
+}) or die "could not connect to database (file '$db_filename')", $DBI::errstr;
 while (<$fh_unsorted_IEs>) {
   chomp;
   print $progressbar->report("parse IE files:       %40b  ETA: %E   \r", $count++);
   s/V0*(\d+-IE)/V$1/; # revert fake version
   my $ret = parse_iexml($_, $flag_recovery);
-  my $dbh = DBI->connect("dbi:SQLite:dbname=$db_filename", "", "", {
-      RaiseError     => 1,
-      sqlite_unicode => 1,
-  }) or die "could not connect to database (file '$db_filename')", $DBI::errstr;
   write_addsql($dbh, $ret);
-  $dbh->disconnect or warn("disconnecting problems, ", $dbh->errstr);
 }
+$dbh->disconnect or warn("disconnecting problems, ", $dbh->errstr);
 say "\rprocessed $count uniq IEs                                                                                      ";
-
 say "";
 
 1;
-- 
GitLab