]> git.sesse.net Git - skvidarsync/commitdiff
Make do with only one commit per sync.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 10 Nov 2023 22:16:23 +0000 (23:16 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 10 Nov 2023 22:16:23 +0000 (23:16 +0100)
bin/sync.pl

index 3c6d7743236783efca1ef1db4068f2e2cda752ab..8ca281d6c195591afc22e62b7c0043a3b7b675d0 100644 (file)
@@ -235,7 +235,6 @@ sub get_group_assignments {
 sub update_assignment_db {
        my ($dbh, $channel, $ts, $assignments) = @_;
 
-       local $dbh->{AutoCommit} = 0;
        my %db_assignments = ();
        my $q = $dbh->prepare('SELECT name,group_name FROM current_group_membership_history WHERE channel=? AND ts=?');
        $q->execute($channel, $ts);
@@ -256,7 +255,6 @@ sub update_assignment_db {
                        $q->execute($channel, $ts, $name, undef);
                }
        }
-       $dbh->commit;
 }
 
 sub get_spreadsheet_with_title {
@@ -483,6 +481,7 @@ sub db_connect {
        if (!defined($dbh)) {
                return undef;
        }
+       $dbh->{AutoCommit} = 0;
        $dbh->do('LISTEN skvupdate') or return undef;
        return $dbh;
 }
@@ -494,6 +493,9 @@ sub run {
        @log = ();
        skv_log("Siste sync startet: " . POSIX::ctime(time));
 
+       # For the logic on the “applied” table below.
+       $dbh->do('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE');
+
        my $token = get_oauth_bearer_token($dbh, $ua);
 
        # Find the newest message, what it is linked to, and what was the one before it (for group diffing).
@@ -720,8 +722,6 @@ sub run {
 
        # Find the list of names we already marked yellow.
        my %have_colors = ();
-       $dbh->{AutoCommit} = 0;
-       $dbh->do('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE');
        $q = $dbh->prepare('SELECT name,color FROM applied WHERE channel=? AND ts=?');
        $q->execute($config::invitation_channel, $invitation_ts);
        while (my $ref = $q->fetchrow_hashref) {
@@ -829,9 +829,7 @@ if ($#ARGV >= 0 && $ARGV[0] eq '--daemon') {
                }
                if (scalar @ready > 0) {  
                        eval {
-                               $dbh->{AutoCommit} = 1;
                                run($dbh, $ua);
-                               $dbh->commit;
                        };
                        if ($@) {
                                warn "Died with: $@";
@@ -841,9 +839,7 @@ if ($#ARGV >= 0 && $ARGV[0] eq '--daemon') {
        }
 } elsif ($#ARGV >= 0 && $ARGV[0] eq '--benchmark') {
        for my $i (0..9) {
-               $dbh->{AutoCommit} = 1;
                run($dbh, $ua);
-               $dbh->commit;
        }
 } else {
        run($dbh, $ua);