21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
29 Defaults to 0, which stands for unlimited. Otherwise the number of
36 Written AFTER quickaccess/distcontext. This time only for the
37 memoize/distlookup table.
39 As we have said before: Just the quickaccess db from sqlite to
40 postgres. Designed to be USED ONLY ONCE. It drops the table before
41 starting work, so if you run it twice, it's OK, but should only be
42 done if the first round was broke or so.
44 Performance? For 64888 records it took 608 seconds.
50 use lib
"$FindBin::Bin/../lib";
56 use File
::Basename
qw(dirname);
57 use File
::Path
qw(mkpath);
62 use Hash
::Util
qw(lock_keys);
65 lock_keys
%Opt, map { /([^=|!]+)/ } @opt;
74 $SIG{INT
} = $SIG{TERM
} = sub { my $sig = shift; warn "Caught $sig\n"; $SIGNAL=1 };
77 use Time
::HiRes
qw(sleep time);
79 use lib
"$FindBin::Bin/../CPAN-Blame/lib";
80 use CPAN
::Blame
::Config
::Cnntp
;
81 my($workdir,$cpan_home,$ext_src);
83 $workdir = File
::Spec
->catdir
84 ($CPAN::Blame
::Config
::Cnntp
::Config
->{solver_vardir
},
86 $cpan_home = $CPAN::Blame
::Config
::Cnntp
::Config
->{cpan_home
};
87 $ext_src = $CPAN::Blame
::Config
::Cnntp
::Config
->{ext_src
};
90 my $dsn = "dbi:SQLite:dbname=$workdir/memoize.db"; # no option any more
93 my($dbi,$sql,@args) = @_;
94 my $success = $dbi->do($sql,undef,@args);
96 my $err = $dbi->errstr;
99 "Warning: error occurred while executing sql[%s]with args[%s]: %s",
101 join(":",map { defined $_ ?
"'$_'" : "<undef>"} @args),
108 my $sldbi = DBI
->connect ($dsn); # return a dbi handle
109 my $slsth0 = $sldbi->prepare("SELECT count(*) from distlookup");
111 my($slcnt) = $slsth0->fetchrow_array();
112 warn "Found $slcnt records in the sqlite table";
113 my $slsql = "SELECT distv,author,upload_date,distroid from distlookup order by distv";
115 $slsql .= " limit $Opt{max}";
118 my $slsth = $sldbi->prepare($slsql);
121 my $pgdbi = DBI
->connect ("dbi:Pg:dbname=analysis");
122 my $pgsql = "DROP TABLE distlookup";
123 my_do_query
($pgdbi, $pgsql);
124 $pgsql = "CREATE TABLE distlookup (
125 distv text primary key,
129 my_do_query
($pgdbi, $pgsql);
130 my $pgsth2 = $pgdbi->prepare("INSERT INTO distlookup
131 (distv,author,upload_date,distroid) values
135 my $lastreport = my $starttime = time;
138 ROW
: while (my(@row) = $slsth->fetchrow_array) {
140 unless ($pgsth2->execute(@row)) {
141 warn sprintf "ALERT: error inserting row/id[%s]: %s\n", $row[0], $sldbi->errstr;
145 my $eta = int((time - $^T
)*($slcnt - $i)/$i);
146 printf "\r%d/%d remaining seconds: %d ", $i, $slcnt, $eta;
150 my $tooktime = time - $starttime;
151 warn "records transferred[$i] tooktime[$tooktime]\n";
155 # cperl-indent-level: 4