From 6517fb930ae915c78ffec491bf98b40a252ea831 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Thu, 15 May 2014 10:30:03 +0200 Subject: [PATCH] Add a new setting to expire persistent rooms Using a dedicated timeout, so you can set it very high, but still remove very old rooms Fix #28 --- conf/vroom.conf.sample | 6 +++++- public/vroom.pl | 34 +++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/conf/vroom.conf.sample b/conf/vroom.conf.sample index e76e8a6..1bfdd0b 100644 --- a/conf/vroom.conf.sample +++ b/conf/vroom.conf.sample @@ -20,8 +20,12 @@ template => 'default', secret => 'ChangeMe!', # App -# Rooms without any activity for that long will be destroyed +# Rooms without any activity for that long (in seconds) will be destroyed inactivityTimeout => 3600, +# Inactivity timeout (in seconds) for persistent rooms +# 0 means they are not deleted. You can use a high number +# so that persistent rooms are kept long enough, but deleted when not used +persistentInactivityTimeout => 0, logLevel => 'info', # ID of the Chrome extension for screen sharing diff --git a/public/vroom.pl b/public/vroom.pl index aba4324..83b0f11 100755 --- a/public/vroom.pl +++ b/public/vroom.pl @@ -62,19 +62,20 @@ app->log->level('info'); our $config = plugin Config => { file => '../conf/vroom.conf', default => { - dbi => 'DBI:mysql:database=vroom;host=localhost', - dbUser => 'vroom', - dbPassword => 'vroom', - signalingServer => 'https://vroom.example.com/', - stunServer => 'stun.l.google.com:19302', - realm => 'vroom', - emailFrom => 'vroom@example.com', - feedbackRecipient => 'admin@example.com', - template => 'default', - inactivityTimeout => 3600, - logLevel => 'info', - chromeExtensionId => 'ecicdpoejfllflombfanbhfpgcimjddn', - sendmail => '/sbin/sendmail' + dbi => 'DBI:mysql:database=vroom;host=localhost', + dbUser => 'vroom', + dbPassword => 'vroom', + signalingServer => 'https://vroom.example.com/', + stunServer => 'stun.l.google.com:19302', + realm => 'vroom', + emailFrom => 'vroom@example.com', + feedbackRecipient => 'admin@example.com', + template => 'default', + inactivityTimeout => 3600, + persistentInactivityTimeout => 0, + logLevel => 'info', + chromeExtensionId => 'ecicdpoejfllflombfanbhfpgcimjddn', + sendmail => '/sbin/sendmail' } }; @@ -193,6 +194,13 @@ helper delete_rooms => sub { $self->db->do("DELETE FROM participants WHERE id IN (SELECT id FROM rooms WHERE activity_timestamp < $timeout AND persistent='0');"); $self->db->do("DELETE FROM rooms WHERE activity_timestamp < $timeout AND persistent='0';"); } || return undef; + if ($config->{persistentInactivityTimeout} && $config->{persistentInactivityTimeout} > 0){ + eval { + my $timeout = time()-$config->{persistentInactivityTimeout}; + $self->db->do("DELETE FROM participants WHERE id IN (SELECT id FROM rooms WHERE activity_timestamp < $timeout AND persistent='1');"); + $self->db->do("DELETE FROM rooms WHERE activity_timestamp < $timeout AND persistent='1';"); + } || return undef; + } return 1; };