http://bugzilla.spamassassin.org/show_bug.cgi?id=3378
Summary: Bayes SQL: fix possible slow query in nspam_nham_change
Product: Spamassassin
Version: SVN Trunk (Latest Devel Version)
Platform: Other
OS/Version: other
Status: NEW
Severity: normal
Priority: P5
Component: Learner
AssignedTo: [EMAIL PROTECTED]
ReportedBy: [EMAIL PROTECTED]
Via Kelsey Cummings:
However, I did catch this query in the slow query log -- never mind why it
was slowed but it seems unoptimal anyway.
UPDATE bayes_vars
SET spam_count = spam_count + '0',
ham_count = ham_count + '1'
WHERE id = '2426';
Who knows what the SQL server is going to do with "spam_count = spam_count
+ '0'" One hopes the SQL server will ignore it but who knows, eh? I
haven't tested this code but it looks good to me. I just typed it up for
you in this email, sorry for not sending you a nice diff.
sub nspam_nham_change {
my ($self, $num_spam, $num_ham) = @_;
return 0 unless (defined($self->{_dbh}));
my $rows;
if ( $num_spam =! 0 && $num_ham != 0 )
{
my $sql = "UPDATE bayes_vars
SET spam_count = spam_count + ?,
ham_count = ham_count + ?
WHERE id = ?";
$rows = $self->{_dbh}->do($sql,
undef,
$num_spam, $num_ham, $self->{_userid});
}
elsif ( $num_spam != 0 )
{
my $sql = "UPDATE bayes_vars
SET spam_count = spam_count + ?,
WHERE id = ?";
$rows = $self->{_dbh}->do($sql,
undef,
$num_spam, $self->{_userid});
}
elsif ( $num_ham != 0 )
{
my $sql = "UPDATE bayes_vars
SET ham_count = ham_count + ?,
WHERE id = ?";
$rows = $self->{_dbh}->do($sql,
undef,
$num_ham, $self->{_userid});
}
else
{
dbg("bayes: nspam_nham_changed: Called with no delta on spam or ham, why?")
return 1; #Someone didn't call us right but we'll return okay
}
unless (defined($rows)) {
dbg("bayes: nspam_nham_change: SQL Error: ".$self->{_dbh}->errstr());
return 0;
}
return 1;
}
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.