]> git.proxmox.com Git - pmg-api.git/commitdiff
PMG::Cluster::sync_generic_mtime_db - correctly start/commit transaction
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 22 Apr 2017 15:50:43 +0000 (17:50 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 22 Apr 2017 15:58:14 +0000 (17:58 +0200)
No need to start transaction if there is no data

PMG/Cluster.pm

index be1ac9d6e40aa20a786756996d95812e7de65b5a..af51d754665b64bd5350202d61a76529d987b01b 100644 (file)
@@ -657,17 +657,18 @@ my $sync_generic_mtime_db = sub {
     eval {
        # use transaction to speedup things
        my $max = 1000; # UPDATE MAX ENTRIES AT ONCE
-       $ldb->begin_work;
        my $count = 0;
        while (my $ref = $sth->fetchrow_hashref()) {
+           $ldb->begin_work if !$count;
+           $mergefunc->($ref);
            if (++$count >= $max) {
                $count = 0;
                $ldb->commit;
-               $ldb->begin_work;
            }
-           $mergefunc->($ref);
            $updates++;
        }
+
+       $ldb->commit if $count;
     };
     if (my $err = $@) {
        $ldb->rollback;