Index: /trunk/tools/czarpoll.pl
===================================================================
--- /trunk/tools/czarpoll.pl	(revision 29291)
+++ /trunk/tools/czarpoll.pl	(revision 29292)
@@ -105,9 +105,21 @@
     my $newState = undef;
     my $nsStatus = undef;
+    my $lastDay = strftime('%Y-%m-%d', localtime);
+    my $today = undef;
 
     while (1) {
 
+        # check whether day has changed. if so, cleanup tables from previous day and optimize
+        $today = strftime('%Y-%m-%d', localtime);
+        if ($czarDb->isBefore($lastDay, $today)) {
+        
+                print "* New day - performing cleanup\n";
+                $czarDb->cleanupDateRange($lastDay, $lastDay, "30 MINUTE");
+                $czarDb->optimize();
+                $lastDay = $today;
+        }
+
         # sort out times
-        $begin =  strftime('%Y-%m-%d 06:35',localtime);
+        $begin = strftime('%Y-%m-%d 06:35',localtime);
         $end = $czarDb->getNowTimestamp();
 
