svn commit: r1937149 - spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore

[email protected]
Newsgroups gmane.mail.spam.spamassassin.cvs
Message-ID <178687135761.2567560.18286165757883729163@svn03-he-fi>
Author: gbechis
Date: Sun Aug 16 09:09:17 2026
New Revision: 1937149

Log:
commit only every 1000 records during `sa-learn --restore`
to improve speed.
bz #6710

Modified:
   spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/MySQL.pm
   spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/PgSQL.pm
   spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/SQL.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/MySQL.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/MySQL.pm	Sun Aug 16 08:52:56 2026	(r1937148)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/MySQL.pm	Sun Aug 16 09:09:17 2026	(r1937149)
@@ -210,7 +210,7 @@ sub seen_put {
   }
 
   dbg("bayes: seen ($msgid) put");
-  $self->{_dbh}->commit();
+  $self->{_dbh}->commit() unless $self->{_in_restore};
   return 1;
 }
 
@@ -1066,7 +1066,7 @@ sub _put_token {
     }
   }
 
-  $self->{_dbh}->commit();
+  $self->{_dbh}->commit() unless $self->{_in_restore};
   return 1;
 }
 

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/PgSQL.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/PgSQL.pm	Sun Aug 16 08:52:56 2026	(r1937148)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/PgSQL.pm	Sun Aug 16 09:09:17 2026	(r1937149)
@@ -211,7 +211,7 @@ sub seen_put {
   }
 
   dbg("bayes: seen ($msgid) put");
-  $self->{_dbh}->commit();
+  $self->{_dbh}->commit() unless $self->{_in_restore};
   return 1;
 }
 
@@ -1005,7 +1005,7 @@ sub _put_token {
 
   $sth->finish();
 
-  $self->{_dbh}->commit();
+  $self->{_dbh}->commit() unless $self->{_in_restore};
 
   return 1;
 }

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/SQL.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/SQL.pm	Sun Aug 16 08:52:56 2026	(r1937148)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/SQL.pm	Sun Aug 16 09:09:17 2026	(r1937149)
@@ -1438,6 +1438,10 @@ sub restore_database {
     return 0;
   }
 
+  # suppress the per-row commit() done by _put_token()/seen_put() during a
+  # restore, so we can batch commits instead of fsyncing on every row
+  local $self->{_in_restore} = 1;
+
   my $token_count = 0;
   my $db_version;
   my $num_spam;
@@ -1473,6 +1477,7 @@ sub restore_database {
 
     if ($line_count % 1000 == 0) {
       print STDERR "." if ($showdots);
+      $self->{_dbh}->commit() if $self->{_dbh}->{AutoCommit} == 0;
     }
 
     if ($line =~ /^v\s+/) { # variable line
@@ -1581,6 +1586,8 @@ sub restore_database {
               : die "error reading dump file: $!";
   close(DUMPFILE) or die "Can't close dump file: $!";
 
+  $self->{_dbh}->commit() if $self->{_dbh}->{AutoCommit} == 0;
+
   print STDERR "\n" if ($showdots);
 
   unless (defined($num_spam)) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.