]> git.sesse.net Git - wloh/blob - sync.pl
Make the Hessian calculation use the new all_matches vector.
[wloh] / sync.pl
1 #! /usr/bin/perl
2 use DBI;
3 use strict;
4 use warnings;
5 no warnings qw(once);
6 use Encode;
7 use Time::HiRes;
8 require './config.pm';
9
10 sub sync_table {
11         my ($mdbh, $sdbh, $table) = @_;
12         my $start = [ Time::HiRes::gettimeofday ];
13         my $data = $mdbh->selectall_arrayref("SELECT * FROM $table");
14         my $elapsed = Time::HiRes::tv_interval($start);
15         #printf "MySQL $table time used: $elapsed\n";
16
17         $start = [ Time::HiRes::gettimeofday ];
18         $sdbh->do("DELETE FROM $table");
19         $sdbh->do("COPY $table FROM STDIN");
20         
21         for my $row (@$data) {
22                 $sdbh->pg_putcopydata(join("\t", map { Encode::decode('iso8859-1', $_ // '\N') } (@$row)) . "\n");
23         }
24         $sdbh->pg_putcopyend();
25         $elapsed = Time::HiRes::tv_interval($start);
26         #printf "PostgreSQL $table time used: $elapsed\n";
27 }
28
29 my $mdbh = DBI->connect($config::master_connstr, $config::master_username, $config::master_password)
30         or die "PostgreSQL connect: " . $DBI::errstr;
31 $mdbh->{AutoCommit} = 0;
32 $mdbh->{RaiseError} = 1;
33
34 my $sdbh = DBI->connect($config::local_connstr, $config::local_username, $config::local_password)
35         or die "PostgreSQL connect: " . $DBI::errstr;
36 $sdbh->{AutoCommit} = 0;
37 $sdbh->{RaiseError} = 1;
38
39 sync_table($mdbh, $sdbh, "Fotballbrukere");
40 sync_table($mdbh, $sdbh, "Fotballdeltagere");
41 sync_table($mdbh, $sdbh, "Fotballresultater");
42 sync_table($mdbh, $sdbh, "Fotballserier");
43
44 $mdbh->rollback();
45 $sdbh->commit();