21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
29 Defaults to 0, which stands for unlimited. Otherwise the number of
36 Just the quickaccess db from sqlite to postgres. Designed to be USED
37 ONLY ONCE. It drops the table before starting work, so if you run it
38 twice, it's OK, but should only be done if the first round was broke
41 Performance? For 49611 records it took 482 seconds.
43 Amazing: the website continued to work while we were running.
49 use lib
"$FindBin::Bin/../lib";
55 use File
::Basename
qw(dirname);
56 use File
::Path
qw(mkpath);
61 use Hash
::Util
qw(lock_keys);
64 lock_keys
%Opt, map { /([^=|!]+)/ } @opt;
73 $SIG{INT
} = $SIG{TERM
} = sub { my $sig = shift; warn "Caught $sig\n"; $SIGNAL=1 };
76 use Time
::HiRes
qw(sleep time);
78 use lib
"$FindBin::Bin/../CPAN-Blame/lib";
79 use CPAN
::Blame
::Config
::Cnntp
;
80 my($workdir,$cpan_home,$ext_src);
82 $workdir = File
::Spec
->catdir
83 ($CPAN::Blame
::Config
::Cnntp
::Config
->{solver_vardir
},
85 $cpan_home = $CPAN::Blame
::Config
::Cnntp
::Config
->{cpan_home
};
86 $ext_src = $CPAN::Blame
::Config
::Cnntp
::Config
->{ext_src
};
89 my $dsn = "dbi:SQLite:dbname=$workdir/quickaccess.db"; # no option any more
92 my($dbi,$sql,@args) = @_;
93 my $success = $dbi->do($sql,undef,@args);
95 my $err = $dbi->errstr;
98 "Warning: error occurred while executing sql[%s]with args[%s]: %s",
100 join(":",map { defined $_ ?
"'$_'" : "<undef>"} @args),
107 my $sldbi = DBI
->connect ($dsn); # return a dbi handle
108 my $slsth0 = $sldbi->prepare("SELECT count(*) from distcontext");
110 my($slcnt) = $slsth0->fetchrow_array();
111 warn "Found $slcnt records in the sqlite table";
112 my $slsql = "SELECT distv,yaml,greenish,dist from distcontext order by distv";
114 $slsql .= " limit $Opt{max}";
117 my $slsth = $sldbi->prepare($slsql);
120 my $pgdbi = DBI
->connect ("dbi:Pg:dbname=analysis");
121 my $pgsql = "DROP TABLE distcontext";
122 my_do_query
($pgdbi, $pgsql);
123 $pgsql = "CREATE TABLE distcontext (
124 distv text primary key,
128 my_do_query
($pgdbi, $pgsql);
129 my $pgsth2 = $pgdbi->prepare("INSERT INTO distcontext
130 (distv,yaml,greenish,dist) values
134 my $lastreport = my $starttime = time;
137 ROW
: while (my(@row) = $slsth->fetchrow_array) {
139 unless ($pgsth2->execute(@row)) {
140 warn sprintf "ALERT: error inserting row/id[%s]: %s\n", $row[0], $sldbi->errstr;
144 my $eta = int((time - $^T
)*($slcnt - $i)/$i);
145 printf "\r%d/%d remaining seconds: %d ", $i, $slcnt, $eta;
149 my $tooktime = time - $starttime;
150 warn "records transferred[$i] tooktime[$tooktime]\n";
154 # cperl-indent-level: 4