client: Remove extra clone, pass big struct by reference (#30716)

Commit titles explain all of the changes

Release Notes:

- N/A
This commit is contained in:
tidely 2025-05-15 01:16:25 +03:00 committed by GitHub
parent 607bfd3b1c
commit 5078f0b5ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -365,7 +365,7 @@ impl Telemetry {
telemetry::event!(
"Editor Edited",
duration = duration,
environment = environment.to_string(),
environment = environment,
is_via_ssh = is_via_ssh
);
}
@ -427,9 +427,8 @@ impl Telemetry {
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_INTERVAL).await;
this.executor.timer(FLUSH_INTERVAL).await;
this.flush_events().detach();
}));
}
@ -480,12 +479,12 @@ impl Telemetry {
self: &Arc<Self>,
// We take in the JSON bytes buffer so we can reuse the existing allocation.
mut json_bytes: Vec<u8>,
event_request: EventRequestBody,
event_request: &EventRequestBody,
) -> Result<Request<AsyncBody>> {
json_bytes.clear();
serde_json::to_writer(&mut json_bytes, &event_request)?;
serde_json::to_writer(&mut json_bytes, event_request)?;
let checksum = calculate_json_checksum(&json_bytes).unwrap_or("".to_string());
let checksum = calculate_json_checksum(&json_bytes).unwrap_or_default();
Ok(Request::builder()
.method(Method::POST)
@ -502,7 +501,7 @@ impl Telemetry {
pub fn flush_events(self: &Arc<Self>) -> Task<()> {
let mut state = self.state.lock();
state.first_event_date_time = None;
let mut events = mem::take(&mut state.events_queue);
let events = mem::take(&mut state.events_queue);
state.flush_events_task.take();
drop(state);
if events.is_empty() {
@ -515,7 +514,7 @@ impl Telemetry {
let mut json_bytes = Vec::new();
if let Some(file) = &mut this.state.lock().log_file {
for event in &mut events {
for event in &events {
json_bytes.clear();
serde_json::to_writer(&mut json_bytes, event)?;
file.write_all(&json_bytes)?;
@ -542,7 +541,7 @@ impl Telemetry {
}
};
let request = this.build_request(json_bytes, request_body)?;
let request = this.build_request(json_bytes, &request_body)?;
let response = this.http_client.send(request).await?;
if response.status() != 200 {
log::error!("Failed to send events: HTTP {:?}", response.status());