Some more prepared queries

master
Daniel Berteaud 10 years ago
parent 3e3f6e09f8
commit 8b01ca6fe9
  1. 16
      vroom.pl

@ -422,9 +422,9 @@ helper delete_participants => sub {
$self->app->log->debug('Removing inactive participants from the database'); $self->app->log->debug('Removing inactive participants from the database');
my $timeout = time()-600; my $timeout = time()-600;
my $sth = eval { my $sth = eval {
$self->db->prepare("DELETE FROM `participants` WHERE (`activity_timestamp` < $timeout OR `activity_timestamp` IS NULL);") $self->db->prepare("DELETE FROM `participants` WHERE (`activity_timestamp` < ? OR `activity_timestamp` IS NULL);")
} || return undef; } || return undef;
$sth->execute() || return undef; $sth->execute($timeout) || return undef;
return 1; return 1;
}; };
@ -434,9 +434,9 @@ helper delete_rooms => sub {
$self->app->log->debug('Removing unused rooms'); $self->app->log->debug('Removing unused rooms');
my $timeout = time()-$config->{'rooms.inactivity_timeout'}; my $timeout = time()-$config->{'rooms.inactivity_timeout'};
my $sth = eval { my $sth = eval {
$self->db->prepare("SELECT `name` FROM `rooms` WHERE `activity_timestamp` < $timeout AND `persistent`='0' AND `owner_password` IS NULL;") $self->db->prepare("SELECT `name` FROM `rooms` WHERE `activity_timestamp` < ? AND `persistent`='0' AND `owner_password` IS NULL;")
} || return undef; } || return undef;
$sth->execute(); $sth->execute($timeout);
my @toDeleteName = (); my @toDeleteName = ();
while (my $room = $sth->fetchrow_array){ while (my $room = $sth->fetchrow_array){
push @toDeleteName, $room; push @toDeleteName, $room;
@ -445,9 +445,9 @@ helper delete_rooms => sub {
if ($config->{'rooms.reserved_inactivity_timeout'} > 0){ if ($config->{'rooms.reserved_inactivity_timeout'} > 0){
$timeout = time()-$config->{'rooms.reserved_inactivity_timeout'}; $timeout = time()-$config->{'rooms.reserved_inactivity_timeout'};
$sth = eval { $sth = eval {
$self->db->prepare("SELECT `name` FROM `rooms` WHERE `activity_timestamp` < $timeout AND `persistent`='0' AND `owner_password` IS NOT NULL;") $self->db->prepare("SELECT `name` FROM `rooms` WHERE `activity_timestamp` < ? AND `persistent`='0' AND `owner_password` IS NOT NULL;")
} || return undef; } || return undef;
$sth->execute(); $sth->execute($timeout);
while (my $room = $sth->fetchrow_array){ while (my $room = $sth->fetchrow_array){
push @toDeleteName, $room; push @toDeleteName, $room;
} }
@ -784,9 +784,9 @@ helper delete_invitations => sub {
# Invitation older than 2 hours doesn't make much sense # Invitation older than 2 hours doesn't make much sense
my $timeout = time()-7200; my $timeout = time()-7200;
my $sth = eval { my $sth = eval {
$self->db->prepare("DELETE FROM `invitations` WHERE `timestamp` < $timeout;") $self->db->prepare("DELETE FROM `invitations` WHERE `timestamp` < ?;")
} || return undef; } || return undef;
$sth->execute() || return undef; $sth->execute($timeout) || return undef;
return 1; return 1;
}; };

Loading…
Cancel
Save