@@ -277,8 +277,8 @@ const Flagsmith = class {
277277
278278 const environmentKey = this . evaluationContext . environment ! . apiKey ;
279279 this . isPipelineFlushing = true ;
280- const eventsToSend = this . pipelineEvents ;
281- this . pipelineEvents = [ ] ;
280+ const eventsToSend = this . pipelineEvents . slice ( 0 , this . evaluationAnalyticsMaxBuffer ) ;
281+ this . pipelineEvents = this . pipelineEvents . slice ( this . evaluationAnalyticsMaxBuffer ) ;
282282 this . pipelineRecordedKeys . clear ( ) ;
283283
284284 const batch : IPipelineEventBatch = {
@@ -302,7 +302,6 @@ const Flagsmith = class {
302302 this . log ( 'Pipeline analytics: flush successful' ) ;
303303 } catch ( err ) {
304304 this . pipelineEvents = eventsToSend . concat ( this . pipelineEvents ) ;
305- this . trimPipelineBuffer ( ) ;
306305 this . log ( 'Pipeline analytics: flush failed, events re-queued' , err ) ;
307306 } finally {
308307 this . isPipelineFlushing = false ;
@@ -1008,13 +1007,6 @@ const Flagsmith = class {
10081007 this . pipelineRecordedKeys . clear ( ) ;
10091008 }
10101009
1011- private trimPipelineBuffer ( ) {
1012- if ( this . pipelineEvents . length > this . evaluationAnalyticsMaxBuffer ) {
1013- const excess = this . pipelineEvents . length - this . evaluationAnalyticsMaxBuffer ;
1014- this . pipelineEvents = this . pipelineEvents . slice ( excess ) ;
1015- }
1016- }
1017-
10181010 // Pipeline event schema — must match the pipeline server's Event struct.
10191011 // To update: 1) IPipelineEvent in types.d.ts 2) event object below 3) tests in test/analytics-pipeline.test.ts
10201012 private recordPipelineEvent ( key : string ) {
@@ -1042,9 +1034,8 @@ const Flagsmith = class {
10421034 } ,
10431035 } ;
10441036 this . pipelineEvents . push ( event ) ;
1045- this . trimPipelineBuffer ( ) ;
10461037
1047- if ( this . pipelineFlushInterval === 0 ) {
1038+ if ( this . pipelineFlushInterval === 0 || this . pipelineEvents . length >= this . evaluationAnalyticsMaxBuffer ) {
10481039 this . flushPipelineAnalytics ( ) ;
10491040 }
10501041 }
0 commit comments