[Rt-commit] rt branch, 4.4/importer-auto-commit, created. rt-4.4.3-37-g6d8909435
? sunnavy
sunnavy at bestpractical.com
Mon Aug 20 09:28:39 EDT 2018
The branch, 4.4/importer-auto-commit has been created
at 6d8909435d7459e27bd9134e9970b84e9d7a4e17 (commit)
- Log -----------------------------------------------------------------
commit 6d8909435d7459e27bd9134e9970b84e9d7a4e17
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Aug 14 00:45:12 2018 +0800
Add --no-auto-commit option for rt-importer
This could boost performance for DB operations.
diff --git a/lib/RT/Migrate/Importer.pm b/lib/RT/Migrate/Importer.pm
index 6eef04532..52d43c209 100644
--- a/lib/RT/Migrate/Importer.pm
+++ b/lib/RT/Migrate/Importer.pm
@@ -71,6 +71,7 @@ sub Init {
DumpObjects => undef,
HandleError => undef,
ExcludeOrganization => undef,
+ AutoCommit => 1,
@_,
);
@@ -81,6 +82,8 @@ sub Init {
$self->{Progress} = $args{Progress};
+ $self->{AutoCommit} = $args{AutoCommit};
+
$self->{HandleError} = sub { 0 };
$self->{HandleError} = $args{HandleError}
if $args{HandleError} and ref $args{HandleError} eq 'CODE';
diff --git a/lib/RT/Migrate/Importer/File.pm b/lib/RT/Migrate/Importer/File.pm
index de3fe84a0..de0d94d7a 100644
--- a/lib/RT/Migrate/Importer/File.pm
+++ b/lib/RT/Migrate/Importer/File.pm
@@ -114,6 +114,7 @@ sub Import {
$self->ReadStream( $fh );
}
+ RT->DatabaseHandle->dbh->commit unless $self->{AutoCommit};
}
$self->CloseStream;
@@ -183,6 +184,8 @@ sub RestoreState {
sub SaveState {
my $self = shift;
+ RT->DatabaseHandle->dbh->commit unless $self->{AutoCommit};
+
my %data;
unshift @{$self->{Files}}, $self->{Filename};
$self->{Seek} = $self->{Position};
diff --git a/sbin/rt-importer.in b/sbin/rt-importer.in
index 6c32e8356..7fc0d106b 100644
--- a/sbin/rt-importer.in
+++ b/sbin/rt-importer.in
@@ -86,7 +86,7 @@ use Getopt::Long;
use Pod::Usage qw//;
use Time::HiRes qw//;
-my %OPT = (resume => 1);
+my %OPT = (resume => 1, 'auto-commit' => 1);
GetOptions(
\%OPT,
"help|?",
@@ -100,6 +100,8 @@ GetOptions(
"ask",
"ignore-errors",
+ "auto-commit!",
+
"dump=s@",
) or Pod::Usage::pod2usage();
@@ -142,12 +144,15 @@ elsif ($OPT{'ignore-errors'}) {
};
}
+RT->DatabaseHandle->AutoCommit(0) unless $OPT{'auto-commit'};
+
my $import = RT::Migrate::Importer::File->new(
Directory => $dir,
OriginalId => $OPT{originalid},
ExcludeOrganization => $OPT{'exclude-organization'},
DumpObjects => $OPT{dump},
Resume => $OPT{resume},
+ AutoCommit => $OPT{'auto-commit'},
HandleError => $error_handler,
);
@@ -280,6 +285,11 @@ serialized data. This is mostly useful for debugging.
Works only in conjunction with C<--list>.
+=item B<--no-auto-commit>
+
+Don't auto commit to database. When this flag is used, it will commit only
+once for each data file. This could boost performance in some cases.
+
=back
-----------------------------------------------------------------------
More information about the rt-commit
mailing list