From 063b7f8d01d8c7ed1a75ea862c93eaf383b6b04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Thu, 4 Jun 2026 14:32:04 +0200 Subject: [PATCH] Run heavy read commands on the blocking pool --- crates/radicle-tauri/src/commands.rs | 18 ++++++++++ crates/radicle-tauri/src/commands/cob/job.rs | 7 ++-- crates/radicle-tauri/src/commands/repo.rs | 38 ++++++++++++-------- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/crates/radicle-tauri/src/commands.rs b/crates/radicle-tauri/src/commands.rs index c8005304d..d9c072905 100644 --- a/crates/radicle-tauri/src/commands.rs +++ b/crates/radicle-tauri/src/commands.rs @@ -6,3 +6,21 @@ pub mod profile; pub mod repo; pub mod startup; pub mod thread; + +use radicle_types::AppState; +use radicle_types::error::Error; + +/// Run a blocking, synchronous port method on the async runtime's blocking +/// pool instead of a worker thread. The port methods do blocking libgit2/COB +/// work; running them inline on an `async` command would pin a runtime worker +/// for the call's full duration and let a slow read (e.g. listing refs or +/// jobs) stall every other command queued behind it. Cloning `AppState` is +/// cheap — it only clones the `Profile` (paths and keys, not open handles). +pub(crate) async fn blocking(ctx: tauri::State<'_, AppState>, f: F) -> Result +where + F: FnOnce(AppState) -> Result + Send + 'static, + T: Send + 'static, +{ + let state = (*ctx).clone(); + tauri::async_runtime::spawn_blocking(move || f(state)).await? +} diff --git a/crates/radicle-tauri/src/commands/cob/job.rs b/crates/radicle-tauri/src/commands/cob/job.rs index 7120bd943..07099d165 100644 --- a/crates/radicle-tauri/src/commands/cob/job.rs +++ b/crates/radicle-tauri/src/commands/cob/job.rs @@ -5,12 +5,13 @@ use radicle_types::error::Error; use radicle_types::traits::job::Jobs; use crate::AppState; +use crate::commands::blocking; #[tauri::command] -pub fn list_jobs( - ctx: tauri::State, +pub async fn list_jobs( + ctx: tauri::State<'_, AppState>, rid: RepoId, sha: git::Oid, ) -> Result, Error> { - ctx.list_jobs(rid, sha) + blocking(ctx, move |ctx| ctx.list_jobs(rid, sha)).await } diff --git a/crates/radicle-tauri/src/commands/repo.rs b/crates/radicle-tauri/src/commands/repo.rs index 74871b951..b01757aea 100644 --- a/crates/radicle-tauri/src/commands/repo.rs +++ b/crates/radicle-tauri/src/commands/repo.rs @@ -6,25 +6,26 @@ use radicle_types::error::Error; use radicle_types::traits::repo::{Repo, Show}; use crate::AppState; +use crate::commands::blocking; #[tauri::command] pub async fn list_repos( ctx: tauri::State<'_, AppState>, show: Show, ) -> Result, Error> { - ctx.list_repos(show) + blocking(ctx, move |ctx| ctx.list_repos(show)).await } #[tauri::command] pub async fn list_repos_summary( ctx: tauri::State<'_, AppState>, ) -> Result, Error> { - ctx.list_repos_summary() + blocking(ctx, |ctx| ctx.list_repos_summary()).await } #[tauri::command] pub async fn repo_count(ctx: tauri::State<'_, AppState>) -> Result { - ctx.repo_count() + blocking(ctx, |ctx| ctx.repo_count()).await } #[tauri::command] @@ -32,7 +33,7 @@ pub async fn list_repo_refs( ctx: tauri::State<'_, AppState>, rid: RepoId, ) -> Result { - ctx.list_repo_refs(rid) + blocking(ctx, move |ctx| ctx.list_repo_refs(rid)).await } #[tauri::command] @@ -40,7 +41,7 @@ pub async fn repo_by_id( ctx: tauri::State<'_, AppState>, rid: RepoId, ) -> Result { - ctx.repo_by_id(rid) + blocking(ctx, move |ctx| ctx.repo_by_id(rid)).await } #[tauri::command] @@ -51,7 +52,7 @@ pub async fn repo_readme( peer: Option, revision: Option, ) -> Result, Error> { - ctx.repo_readme(rid, sha, peer, revision) + blocking(ctx, move |ctx| ctx.repo_readme(rid, sha, peer, revision)).await } #[tauri::command] @@ -63,7 +64,10 @@ pub async fn repo_tree( peer: Option, revision: Option, ) -> Result { - ctx.repo_tree(rid, path, sha, peer, revision) + blocking(ctx, move |ctx| { + ctx.repo_tree(rid, path, sha, peer, revision) + }) + .await } #[tauri::command] @@ -73,7 +77,7 @@ pub async fn repo_blob( path: std::path::PathBuf, sha: Option, ) -> Result { - ctx.repo_blob(rid, path, sha) + blocking(ctx, move |ctx| ctx.repo_blob(rid, path, sha)).await } #[tauri::command] @@ -83,7 +87,7 @@ pub async fn diff_stats( base: git::Oid, head: git::Oid, ) -> Result { - ctx.diff_stats(rid, base, head) + blocking(ctx, move |ctx| ctx.diff_stats(rid, base, head)).await } #[tauri::command] @@ -93,7 +97,7 @@ pub async fn list_commits( base: String, head: String, ) -> Result, Error> { - ctx.list_commits(rid, base, head) + blocking(ctx, move |ctx| ctx.list_commits(rid, base, head)).await } #[tauri::command] @@ -104,7 +108,10 @@ pub async fn get_commit_diff( unified: Option, highlight: Option, ) -> Result { - ctx.get_commit_diff(rid, sha, unified, highlight) + blocking(ctx, move |ctx| { + ctx.get_commit_diff(rid, sha, unified, highlight) + }) + .await } #[tauri::command] @@ -117,7 +124,10 @@ pub async fn list_repo_commits( skip: Option, take: Option, ) -> Result>, Error> { - ctx.list_repo_commits(rid, head, peer, revision, skip, take) + blocking(ctx, move |ctx| { + ctx.list_repo_commits(rid, head, peer, revision, skip, take) + }) + .await } #[tauri::command] @@ -126,7 +136,7 @@ pub async fn repo_commit_count( rid: RepoId, head: git::Oid, ) -> Result { - ctx.repo_commit_count(rid, head) + blocking(ctx, move |ctx| ctx.repo_commit_count(rid, head)).await } #[tauri::command] @@ -137,7 +147,7 @@ pub async fn repo_commit( peer: Option, revision: Option, ) -> Result { - ctx.repo_commit(rid, sha, peer, revision) + blocking(ctx, move |ctx| ctx.repo_commit(rid, sha, peer, revision)).await } #[tauri::command]