fix: CPU usage after launching a cluster

This commit is contained in:
LynithDev 2024-10-27 15:03:42 +01:00
parent 24f58bec2d
commit 451987a326
3 changed files with 12 additions and 17 deletions

View file

@ -70,8 +70,6 @@ pub async fn run_app<F: FnOnce(&tauri::AppHandle<tauri::Wry>) + Send + 'static>(
.manage(ext::updater::State::default())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_deep_link::init())
// TODO: add back tauri-plugin-window-state -- it's buggy at the moment
// .plugin(tauri_plugin_window_state::Builder::default().build())
.plugin(api::init())
.menu(tauri::menu::Menu::new)
.invoke_handler(prebuild.invoke_handler())

View file

@ -750,8 +750,7 @@ impl Clusters {
pub fn sync_cluster(cluster_path: ClusterPath) {
tokio::task::spawn(async move {
let span = tracing::span!(tracing::Level::INFO, "sync_cluster");
let res = async {
let _span = span.enter();
let res = span.in_scope(|| async {
let state = State::get().await?;
let dirs = &state.directories;
let mut clusters = state.clusters.write().await;
@ -781,7 +780,7 @@ impl Clusters {
});
}
Ok::<(), crate::Error>(())
}
})
.await;
match res {

View file

@ -438,22 +438,20 @@ impl Processor {
let mut stdout = BufReader::new(stdout).lines();
let mut stderr = BufReader::new(stderr).lines();
while let Ok(line) = tokio::select! {
while let Ok(Some(line)) = tokio::select! {
line = stdout.next_line() => line,
line = stderr.next_line() => line,
} {
if let Some(line) = line {
let mut censored = line.clone();
for (key, value) in &censors {
censored = censored.replace(key, value);
}
if let Err(err) =
send_process(uuid, pid, ProcessPayloadType::Logging, &censored).await
{
tracing::warn!("failed to send process log: {}", err);
};
let mut censored = line.clone();
for (key, value) in &censors {
censored = censored.replace(key, value);
}
if let Err(err) =
send_process(uuid, pid, ProcessPayloadType::Logging, &censored).await
{
tracing::warn!("failed to send process log: {}", err);
};
}
});