From 00682b8903a8553b5d34b4f502afe6c50c027f23 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Tue, 16 Jan 2024 18:31:00 -0500 Subject: [PATCH] Do not reset timer for each reported event --- crates/client/src/telemetry.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 32cf9efba2..102362c422 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -457,20 +457,24 @@ impl Telemetry { return; } + if state.flush_events_task.is_none() { + let this = self.clone(); + let executor = self.executor.clone(); + state.flush_events_task = Some(self.executor.spawn(async move { + executor.timer(FLUSH_DEBOUNCE_INTERVAL).await; + this.flush_events(); + })); + } + let signed_in = state.metrics_id.is_some(); state.events_queue.push(EventWrapper { signed_in, event }); + dbg!(&state.events_queue.len()); + if state.installation_id.is_some() { if state.events_queue.len() >= MAX_QUEUE_LEN { drop(state); self.flush_events(); - } else { - let this = self.clone(); - let executor = self.executor.clone(); - state.flush_events_task = Some(self.executor.spawn(async move { - executor.timer(FLUSH_DEBOUNCE_INTERVAL).await; - this.flush_events(); - })); } } } @@ -534,6 +538,7 @@ impl Telemetry { release_channel: state.release_channel, events, }; + dbg!("flush", &request_body); json_bytes.clear(); serde_json::to_writer(&mut json_bytes, &request_body)?; }