From 00682b8903a8553b5d34b4f502afe6c50c027f23 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Tue, 16 Jan 2024 18:31:00 -0500 Subject: [PATCH 1/3] 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)?; } From 0c59f510d2d539c6a5196b414d2dff57c7654dec Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Tue, 16 Jan 2024 18:33:43 -0500 Subject: [PATCH 2/3] Remove `dbg!()`s --- crates/client/src/telemetry.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 102362c422..8e8aa4942c 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -469,8 +469,6 @@ impl Telemetry { 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); @@ -538,7 +536,6 @@ impl Telemetry { release_channel: state.release_channel, events, }; - dbg!("flush", &request_body); json_bytes.clear(); serde_json::to_writer(&mut json_bytes, &request_body)?; } From 54dcb1d33ca1dcf4a183c38cf3e0f33b87a63ce0 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Tue, 16 Jan 2024 18:34:52 -0500 Subject: [PATCH 3/3] Rename variable --- crates/client/src/telemetry.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 8e8aa4942c..5ee039a8cb 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -143,10 +143,10 @@ const MAX_QUEUE_LEN: usize = 5; const MAX_QUEUE_LEN: usize = 50; #[cfg(debug_assertions)] -const FLUSH_DEBOUNCE_INTERVAL: Duration = Duration::from_secs(1); +const FLUSH_INTERVAL: Duration = Duration::from_secs(1); #[cfg(not(debug_assertions))] -const FLUSH_DEBOUNCE_INTERVAL: Duration = Duration::from_secs(60 * 5); +const FLUSH_INTERVAL: Duration = Duration::from_secs(60 * 5); impl Telemetry { pub fn new(client: Arc, cx: &mut AppContext) -> Arc { @@ -461,7 +461,7 @@ impl Telemetry { 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; + executor.timer(FLUSH_INTERVAL).await; this.flush_events(); })); }