mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 01:02:01 +03:00
refactor(tauri): parallelize load_extensions via async blocking pool
Replaces the synchronous, blocking file-read loop in the `load_extensions` Tauri command with concurrent execution using `tauri::async_runtime::spawn_blocking` and `futures::future::join_all`. This prevents blocking the IPC thread during startup when loading multiple user scripts, significantly improving performance for users with many extensions. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
c958f30662
commit
be0eb86cd0
2 changed files with 15 additions and 9 deletions
4
src-tauri/Cargo.lock
generated
4
src-tauri/Cargo.lock
generated
|
|
@ -4376,9 +4376,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.52.3"
|
version = "1.53.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe"
|
checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
|
|
|
||||||
|
|
@ -631,18 +631,24 @@ fn extensions_dir(app: &AppHandle) -> PathBuf {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn load_extensions(app: AppHandle) -> Vec<ExtensionScript> {
|
async fn load_extensions(app: AppHandle) -> Vec<ExtensionScript> {
|
||||||
let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
if let Ok(entries) = fs::read_dir(extensions_dir(&app)) {
|
if let Ok(entries) = fs::read_dir(extensions_dir(&app)) {
|
||||||
|
let mut tasks = Vec::new();
|
||||||
for entry in entries.flatten() {
|
for entry in entries.flatten() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
if path.extension().is_some_and(|e| e == "js") {
|
if path.extension().is_some_and(|e| e == "js") {
|
||||||
if let Ok(code) = fs::read_to_string(&path) {
|
let name = entry.file_name().to_string_lossy().into_owned();
|
||||||
out.push(ExtensionScript {
|
tasks.push(tauri::async_runtime::spawn_blocking(move || {
|
||||||
name: entry.file_name().to_string_lossy().into_owned(),
|
fs::read_to_string(&path)
|
||||||
code,
|
.ok()
|
||||||
});
|
.map(|code| ExtensionScript { name, code })
|
||||||
}
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for task in tasks {
|
||||||
|
if let Ok(Some(script)) = task.await {
|
||||||
|
out.push(script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue