You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by fe...@apache.org on 2004/07/16 04:44:45 UTC

svn commit: rev 22946 - in spamassassin/trunk: . lib/Mail/SpamAssassin lib/Mail/SpamAssassin/BayesStore

Author: felicity
Date: Thu Jul 15 19:44:44 2004
New Revision: 22946

Modified:
   spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm
   spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/DBM.pm
   spamassassin/trunk/sa-learn.raw
Log:
bug 3483: modify bayes sync_due() behavior, don't sync based on 'no sync in at least 1 day' if there hasn't been a sync before.  add an opportunistic journal sync call to is_scan_available() so that learn_to_journal w/out already having a db initialized will work.  add code so that is_scan_available() and scan() certify that they'll untie the db, overriding the global version appropriately.

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm	(original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Bayes.pm	Thu Jul 15 19:44:44 2004
@@ -1109,22 +1109,39 @@
 
 
 # Check to make sure we can tie() the DB, and we have enough entries to do a scan
+# if we're told the caller will untie(), go ahead and leave the db tied.
 sub is_scan_available {
   my $self = shift;
 
   return 0 unless $self->{conf}->{use_bayes};
   return 0 unless $self->{store}->tie_db_readonly();
 
+  # We need the DB to stay tied, so if the journal sync occurs, don't untie!
+  my $caller_untie = $self->{main}->{learn_caller_will_untie};
+  $self->{main}->{learn_caller_will_untie} = 1;
+
+  # Do a journal sync if necessary.  Do this before the nspam_nham_get()
+  # call since the sync may cause an update in the number of messages
+  # learnt.
+  $self->opportunistic_calls(1);
+
+  # Reset the variable appropriately
+  $self->{main}->{learn_caller_will_untie} = $caller_untie;
+
   my ($ns, $nn) = $self->{store}->nspam_nham_get();
 
   if ($ns < $self->{conf}->{bayes_min_spam_num}) {
     dbg("bayes: Not available for scanning, only $ns spam(s) in Bayes DB < ".$self->{conf}->{bayes_min_spam_num});
-    $self->{store}->untie_db();
+    if (!$self->{main}->{learn_caller_will_untie}) {
+      $self->{store}->untie_db();
+    }
     return 0;
   }
   if ($nn < $self->{conf}->{bayes_min_ham_num}) {
     dbg("bayes: Not available for scanning, only $nn ham(s) in Bayes DB < ".$self->{conf}->{bayes_min_ham_num});
-    $self->{store}->untie_db();
+    if (!$self->{main}->{learn_caller_will_untie}) {
+      $self->{store}->untie_db();
+    }
     return 0;
   }
 
@@ -1138,6 +1155,11 @@
   my ($self, $permsgstatus, $msg) = @_;
   my $score;
 
+  # When we're doing a scan, we'll guarantee that we'll do the untie,
+  # so override the global setting until we're done.
+  my $caller_untie = $self->{main}->{learn_caller_will_untie};
+  $self->{main}->{learn_caller_will_untie} = 1;
+
   goto skip if ($self->ignore_message($permsgstatus));
 
   goto skip unless $self->is_scan_available();
@@ -1258,9 +1280,19 @@
     dbg ("bayes: not scoring message, returning undef");
   }
 
+  # Take any opportunistic actions we can take
   $self->opportunistic_calls();
+
+  # Do any cleanup we need to do
   $self->{store}->cleanup();
-  $self->{store}->untie_db();
+
+  # Reset the value accordingly
+  $self->{main}->{learn_caller_will_untie} = $caller_untie;
+
+  # If our caller won't untie the db, we need to do it.
+  if (!$caller_untie) {
+    $self->{store}->untie_db();
+  }
 
   $permsgstatus->{tag_data}{BAYESTCHAMMY} = $tcount_hammy;
   $permsgstatus->{tag_data}{BAYESTCSPAMMY} = $tcount_spammy;
@@ -1271,7 +1303,7 @@
 }
 
 sub opportunistic_calls {
-  my($self) = @_;
+  my($self, $journal_only) = @_;
 
   # If we're not already tied, abort.
   if (!$self->{store}->db_readable()) {
@@ -1287,7 +1319,7 @@
   }
 
   # handle expiry and syncing
-  if ($self->{store}->expiry_due()) {
+  if (!$journal_only && $self->{store}->expiry_due()) {
     dbg("bayes: opportunistic call found expiry due");
 
     # sync will bring the DB R/W as necessary, and the expire will remove

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/DBM.pm
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/DBM.pm	(original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/BayesStore/DBM.pm	Thu Jul 15 19:44:44 2004
@@ -737,8 +737,9 @@
   # Yes if the file size is larger than the specified maximum size.
   return 1 if (-s _ > $conf->{bayes_journal_max_size});
 
-  # Yes if it's been at least a day since the last sync.
-  return 1 if (time - $vars[7] > 86400);
+  # Yes there has been a sync before, and if it's been at least a day
+  # since that sync.
+  return 1 if (($vars[7] > 0) && (time - $vars[7] > 86400));
 
   # No, I guess not.
   return 0;

Modified: spamassassin/trunk/sa-learn.raw
==============================================================================
--- spamassassin/trunk/sa-learn.raw	(original)
+++ spamassassin/trunk/sa-learn.raw	Thu Jul 15 19:44:44 2004
@@ -959,7 +959,8 @@
 
 =over 4
 
-=item - at least 1 day has passed since the last journal sync
+=item - a journal sync has previously occured, and at least 1 day has
+passed since that sync
 
 =back