From 6933f8ccafa0ae4f195e65921541e5eeb12b05fb Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Mon, 18 Nov 2024 04:46:40 +0100 Subject: [PATCH] perf: I. AM. SPEED. 0.04s per package --- Cargo.lock | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + README.md | 2 +- src/main.rs | 40 +++++++++++++++++++++++----------------- 4 files changed, 76 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb07404..6024317 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -275,6 +275,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.31" @@ -282,6 +297,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -290,6 +306,34 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-sink" version = "0.3.31" @@ -308,10 +352,16 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -752,6 +802,7 @@ version = "0.1.2" dependencies = [ "clap", "colored", + "futures", "lazy_static", "reqwest", "serde", diff --git a/Cargo.toml b/Cargo.toml index 6e99066..5ea3412 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ gitlab = ["reqwest"] [dependencies] clap = { version = "4.5.21", features = ["derive", "color", "error-context", "help", "std", "usage"], default-features = false } colored = "2.1.0" +futures = "0.3.31" lazy_static = "1.5.0" reqwest = { version = "0.12.9", features = ["__tls", "charset", "default-tls", "h2", "http2", "json"], default-features = false, optional = true } serde = { version = "1.0.215", features = ["derive"] } diff --git a/README.md b/README.md index adc2138..a37931f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ you may encounter some issues. please consider [submitting feedback](https://git | command | time per **updated** package | details | |---------------|------------------------------|--------------------------------------------------------| -| `nvrs` | ~ 0.09s | **API requests included**
depends on internet speed | +| `nvrs` | ~ 0.04s | **API requests included**
depends on internet speed | | `nvrs --cmp` | ~ 0.0008s | depends on disk speed | | `nvrs --take` | ~ 0.001s | depends on disk speed | diff --git a/src/main.rs b/src/main.rs index 9e93112..d7f9400 100644 --- a/src/main.rs +++ b/src/main.rs @@ -155,31 +155,37 @@ copies or substantial portions of the Software.", let (config_content, _, keyfile) = config::load(cli.custom_config); let (_, mut newver) = verfiles::load(config_content.__config__.clone()).unwrap(); + let tasks: Vec<_> = config_content + .packages + .clone() + .into_iter() + .map(|pkg| tokio::spawn(run_source(pkg, keyfile.clone()))) + .collect(); + + let mut results = futures::future::join_all(tasks).await; + for package in config_content.packages { - if let Some(pkg) = newver.data.data.iter_mut().find(|p| p.0 == &package.0) { - if let Some(latest) = run_source(package.clone(), keyfile.clone()).await { - let latest_tag = latest.tag_name.replacen(&package.1.prefix, "", 1); + let release = results.remove(0).unwrap().unwrap(); + let tag = release.tag_name.replacen(&package.1.prefix, "", 1); - if pkg.1.version != latest_tag { - println!( - "| {} {} -> {}", - package.0.blue(), - pkg.1.version.red(), - latest_tag.green() - ); - pkg.1.version = latest_tag; - } + if let Some(pkg) = newver.data.data.iter_mut().find(|p| p.0 == &package.0) { + if pkg.1.version != tag { + println!( + "| {} {} -> {}", + package.0.blue(), + pkg.1.version.red(), + tag.green() + ); + pkg.1.version = tag; } - } else if let Some(latest) = run_source(package.clone(), keyfile.clone()).await { - let tag = latest.tag_name.replacen(&package.1.prefix, "", 1); - + } else { println!("| {} {} -> {}", package.0.blue(), "NONE".red(), tag.green()); newver.data.data.insert( package.0, verfiles::Package { version: tag, - gitref: format!("refs/tags/{}", latest.tag_name), - url: latest.html_url, + gitref: format!("refs/tags/{}", release.tag_name), + url: release.html_url, }, ); }