From 7fb0e1eaf7a59f7628f1ecc3da55ecc389e9b8dc Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 26 Nov 2018 15:02:34 -0500 Subject: [PATCH 1/2] Cache All StorageAreas and just to next event if we find the event somewhere other than where it should be. --- scripts/zmaudit.pl.in | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/zmaudit.pl.in b/scripts/zmaudit.pl.in index 678c07d3c..a455af74a 100644 --- a/scripts/zmaudit.pl.in +++ b/scripts/zmaudit.pl.in @@ -176,8 +176,10 @@ MAIN: while( $loop ) { } # end while can't connect to the db my @Storage_Areas; + my @all_Storage_Areas = ZoneMinder::Storage->find(); + if ( defined $storage_id ) { - @Storage_Areas = ZoneMinder::Storage->find( Id=>$storage_id ); + @Storage_Areas = map { $$_{Id} == $storage_id ? $_ : () } @all_Storage_Areas; if ( !@Storage_Areas ) { Error("No Storage Area found with Id $storage_id"); Term(); @@ -403,7 +405,7 @@ MAIN: while( $loop ) { $$Event{RelativePath} = $event_dir; $Event->MonitorId( $monitor_dir ); $Event->StorageId( $Storage->Id() ); - $Event->StartTime( POSIX::strftime('%Y-%m-%d %H:%M:%S', gmtime(time_of_youngest_file($$Event{Path})) ) ); + $Event->StartTime( POSIX::strftime('%Y-%m-%d %H:%M:%S', gmtime(time_of_youngest_file($Event->Path())) ) ); } # end foreach event } @@ -523,7 +525,7 @@ MAIN: while( $loop ) { # If we found the monitor in the file system my $fs_events = $fs_monitors->{$db_monitor}; - while ( my ( $db_event, $age ) = each( %$db_events ) ) { +EVENT: while ( my ( $db_event, $age ) = each( %$db_events ) ) { if ( ! ($fs_events and defined( $fs_events->{$db_event} ) ) ) { Debug("Don't have an fs event for $db_event"); my $Event = ZoneMinder::Event->find_one( Id=>$db_event ); @@ -533,14 +535,15 @@ MAIN: while( $loop ) { } Debug("Event $db_event is not in fs. Should have been at ".$Event->Path()); # Check for existence in other Storage Areas - foreach my $Storage ( ZoneMinder::Storage->find( ( $$Event{StorageId} ? ( 'Id !='=>$$Event{StorageId} ) : () ) ) ) { + foreach my $Storage ( @all_Storage_Areas ) { + next if $$Storage{Id} == $$Event{StorageId}; + my $path = $Storage->Path().'/'.$Event->RelativePath(); if ( -e $path ) { Info("Event $$Event{Id} found at $path instead of $$Event{Path}"); if ( confirm('update', 'updating') ) { $Event->save({StorageId=>$$Storage{Id}}); - $Event->Path(undef);# Refresh Path - last; + next EVENT; } } else { Debug("$$Event{Id} Not found at $path"); From d6fb4e19105115c827c39697460e79b002dd007e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 26 Nov 2018 15:09:04 -0500 Subject: [PATCH 2/2] Add StorageId function to clear Storage when you set a new StorageId. Clear Path when assigning a new StorageArea --- scripts/ZoneMinder/lib/ZoneMinder/Event.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm index 5916f8cdb..50eef1d6f 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm @@ -483,9 +483,23 @@ sub delete_files { } } # end sub delete_files +sub StorageId { + my $event = shift; + if ( @_ ) { + $$event{StorageId} = shift; + delete $$event{Storage}; + delete $$event{Path}; + } + return $$event{StorageId}; +} + sub Storage { if ( @_ > 1 ) { $_[0]{Storage} = $_[1]; + if ( $_[0]{Storage} ) { + $_[0]{StorageId} = $_[0]{Storage}->Id(); + delete $_[0]{Path}; + } } if ( ! $_[0]{Storage} ) { $_[0]{Storage} = new ZoneMinder::Storage($_[0]{StorageId});