643
# tok_touch_all as proposed in bug 6444, executes one update for each token;
644
# might run faster with some (older?) versions of PostgreSQL
645
# (to switch: rename this one to tok_touch_all and stash the other one away)
647
sub tok_touch_all_6444 {
648
my ($self, $tokens, $atime) = @_;
650
return 0 unless (defined($self->{_dbh}));
652
return 1 unless (scalar(@{$tokens}));
655
"UPDATE bayes_token SET atime=? WHERE id=? AND token=? AND atime < ?";
657
my $sth = $self->{_dbh}->prepare_cached($sql);
658
unless (defined($sth)) {
659
dbg("bayes: tok_touch_all: SQL error: ".$self->{_dbh}->errstr());
663
my $bytea_type = { pg_type => DBD::Pg::PG_BYTEA };
664
$sth->bind_param(1, $atime);
665
$sth->bind_param(2, $self->{_userid});
666
# $sth->bind_param(3, $token, $bytea_type); # later
667
$sth->bind_param(4, $atime);
669
$self->{_dbh}->begin_work();
672
foreach my $token (@$tokens) {
673
$sth->bind_param(3, $token, $bytea_type);
674
my $rc = $sth->execute();
676
dbg("bayes: tok_touch_all: SQL error: ".$self->{_dbh}->errstr());
677
$self->{_dbh}->rollback();
680
my $rows = $sth->rows;
681
unless (defined($rows) && $rows >= 0) {
682
dbg("bayes: tok_touch_all: SQL error: ".$self->{_dbh}->errstr());
683
$self->{_dbh}->rollback();
686
if ($rows > 0) { $n_updates++ }
689
# if we didn't update a row then no need to update newest_token_age
690
if ($n_updates) { # update newest_token_age
691
# need to check newest_token_age
692
# no need to check oldest_token_age since we would only update if the
693
# atime was newer than what is in the database
694
my $sql_upd_age = "UPDATE bayes_vars SET newest_token_age = ?".
695
" WHERE id = ? AND newest_token_age < ?";
696
my $rows = $self->{_dbh}->do($sql_upd_age,
697
undef, $atime, $self->{_userid}, $atime);
698
unless (defined($rows) && $rows >= 0) {
699
dbg("bayes: tok_touch_all: SQL error: ".$self->{_dbh}->errstr());
700
$self->{_dbh}->rollback();
704
$self->{_dbh}->commit();
705
dbg("bayes: tok_touch_all: updated %d tokens", $n_updates);
709
# original tok_touch_all (not the one proposed in bug 6444),
710
# executes one update for all token using an IN operator;
711
# seems to run faster with PostgreSQL 8.3.14 than the alternative
643
713
sub tok_touch_all {
644
714
my ($self, $tokens, $atime) = @_;
728
sub tok_touch_allold {
729
my ($self, $tokens, $atime) = @_;
731
return 0 unless (defined($self->{_dbh}));
733
return 1 unless (scalar(@{$tokens}));
735
my $tokenarray = join(",", map { '"' . _quote_bytea($_) . '"' } sort @{$tokens});
737
my $sth = $self->{_dbh}->prepare("select touch_tokens($self->{_userid}, $self->{_esc_prefix}'{$tokenarray}', $atime)");
739
unless (defined($sth)) {
740
dbg("bayes: tok_touch_all: SQL error: ".$self->{_dbh}->errstr());
741
$self->{_dbh}->rollback();
745
my $rc = $sth->execute();
748
dbg("bayes: tok_touch_all: SQL error: ".$self->{_dbh}->errstr());
749
$self->{_dbh}->rollback();
755
$self->{_dbh}->commit();
762
799
public instance (Boolean) cleanup ()