diff --git a/src/zm_config.h.in b/src/zm_config.h.in index 01098c90f..1df1edf16 100644 --- a/src/zm_config.h.in +++ b/src/zm_config.h.in @@ -45,6 +45,7 @@ #define ZM_SCALE_BASE 100 // The factor by which we bump up 'scale' to simulate FP #define ZM_RATE_BASE 100 // The factor by which we bump up 'rate' to simulate FP +#define ZM_SQL_BATCH_SIZE 50 // Limit the size of multi-row SQL statements #define ZM_SQL_SML_BUFSIZ 256 // Size of SQL buffer #define ZM_SQL_MED_BUFSIZ 1024 // Size of SQL buffer #define ZM_SQL_LGE_BUFSIZ 8192 // Size of SQL buffer diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 47ac0e9ba..827904bbd 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -489,11 +489,18 @@ void Event::updateNotes( const StringSetMap &newNoteSetMap ) } void Event::AddFrames( int n_frames, Image **images, struct timeval **timestamps ) +{ + for (int i = 0; i < n_frames; i += ZM_SQL_BATCH_SIZE) { + AddFramesInternal(n_frames, i, images, timestamps); + } +} + +void Event::AddFramesInternal( int n_frames, int start_frame, Image **images, struct timeval **timestamps ) { static char sql[ZM_SQL_LGE_BUFSIZ]; strncpy( sql, "insert into Frames ( EventId, FrameId, TimeStamp, Delta ) values ", sizeof(sql) ); int frameCount = 0; - for ( int i = 0; i < n_frames; i++ ) + for ( int i = start_frame; i < n_frames && i - start_frame < ZM_SQL_BATCH_SIZE; i++ ) { if ( !timestamps[i]->tv_sec ) { diff --git a/src/zm_event.h b/src/zm_event.h index 7029a9f5c..f50a5bf06 100644 --- a/src/zm_event.h +++ b/src/zm_event.h @@ -133,6 +133,9 @@ public: void AddFrames( int n_frames, Image **images, struct timeval **timestamps ); void AddFrame( Image *image, struct timeval timestamp, int score=0, Image *alarm_frame=NULL ); +private: + void AddFramesInternal( int n_frames, int start_frame, Image **images, struct timeval **timestamps ); + public: static const char *getSubPath( struct tm *time ) {