Apply INSERTs in Event::AddFrames in batches to avoid excessive query length
This commit is contained in:
parent
54512ff6b3
commit
79c7a1b255
|
@ -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
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue