diff --git a/db/zm_update-1.31.19.sql b/db/zm_update-1.31.19.sql index 1ca3a7893..43c9c5005 100644 --- a/db/zm_update-1.31.19.sql +++ b/db/zm_update-1.31.19.sql @@ -93,7 +93,25 @@ end; delimiter ; -ALTER TABLE Events DROP INDEX Archived; -ALTER TABLE Events DROP INDEX Frames; -CREATE INDEX Events_StorageId_idx on Events (StorageId); +set @exist := (select count(*) from information_schema.statistics where table_name = 'Events' and index_name = 'Archived' and table_schema = database()); +set @sqlstmt := if( @exist > 0, 'DROP INDEX Archived ON Events', "SELECT 'Archived INDEX is already removed.'"); +PREPARE stmt FROM @sqlstmt; +EXECUTE stmt; + +set @exist := (select count(*) from information_schema.statistics where table_name = 'Events' and index_name = 'Frames' and table_schema = database()); +set @sqlstmt := if( @exist > 0, 'DROP INDEX Frames ON Events', "SELECT 'Frames INDEX is already removed.'"); +PREPARE stmt FROM @sqlstmt; +EXECUTE stmt; + +set @exist := (select count(*) from information_schema.statistics where table_name = 'Events' and index_name = 'Events_StorageId_idx' and table_schema = database()); +set @sqlstmt := if( @exist > 0, "SELECT 'Index Events_StorageId_idx already exists.'", 'CREATE INDEX Events_StorageId_idx on Events (StorageId)'); +PREPARE stmt FROM @sqlstmt; +EXECUTE stmt; + +set @exist := (select count(*) from information_schema.statistics where table_name = 'Events' and index_name = 'Events_EndTime_DiskSpace_idx' and table_schema = database()); +set @sqlstmt := if( @exist > 0, "SELECT 'Index Events_EndTime_DiskSpace_idx already exists.'", 'CREATE INDEX Events_EndTime_DiskSpace_idx on Events (EndTime, DiskSpace)'); +PREPARE stmt FROM @sqlstmt; +EXECUTE stmt; + +UPDATE Storage SET DiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE StorageId=Storage.Id); diff --git a/scripts/zmwatch.pl.in b/scripts/zmwatch.pl.in index 54964d3b0..2c55a8b75 100644 --- a/scripts/zmwatch.pl.in +++ b/scripts/zmwatch.pl.in @@ -119,7 +119,6 @@ while( 1 ) { or Fatal( "Can't execute: ".$sth->errstr() ); while( my $monitor = $sth->fetchrow_hashref() ) { - my $now = time(); next if $monitor->{Function} eq 'None'; my $restart = 0;