From be5c6371bb68548711bfc440cad8f9a945493713 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 8 Jun 2021 12:50:50 -0400 Subject: [PATCH] zmstats.pl: add use warnings. Fix log deletion only ever deleting 100 when it should delete more in a loop. Add deleting more than 100 sessions. Fix loop not terminating on Ctrl-C --- scripts/zmstats.pl.in | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/zmstats.pl.in b/scripts/zmstats.pl.in index 3c86aada6..a03f68ada 100644 --- a/scripts/zmstats.pl.in +++ b/scripts/zmstats.pl.in @@ -1,5 +1,6 @@ #!@PERL_EXECUTABLE@ -wT use strict; +use warnings; use bytes; # ========================================================================== @@ -79,14 +80,18 @@ while (!$zm_terminate) { } my $rows; do { - my $rows = zmDbDo('DELETE FROM `Logs` WHERE `TimeKey` < unix_timestamp(now() - interval '.$Config{ZM_LOG_DATABASE_LIMIT}.') LIMIT 100'); - Debug("Deleted $rows log table entries by time") if defined $rows; - } while ($rows); + $rows = zmDbDo('DELETE FROM `Logs` WHERE `TimeKey` < unix_timestamp(now() - interval '.$Config{ZM_LOG_DATABASE_LIMIT}.') LIMIT 100'); + Debug("Deleted $rows log table entries by time") if $rows; + } while ($rows and ($rows == 100) and !$zm_terminate); } } # end if ZM_LOG_DATABASE_LIMIT - # Delete any sessions that are more ethan a week old. Limiting to 100 because mysql sucks - zmDbDo('DELETE FROM Sessions WHERE access < ? LIMIT 100', time - (60*60*24*7)); + my $rows; + do { + # Delete any sessions that are more than a week old. Limiting to 100 because mysql sucks + $rows = zmDbDo('DELETE FROM Sessions WHERE access < ? LIMIT 100', time - (60*60*24*7)); + Debug("Deleted $rows sessions") if $rows; + } while ($rows and ($rows == 100) and !$zm_terminate); sleep($Config{ZM_STATS_UPDATE_INTERVAL}); } # end while (!$zm_terminate)