Skip to content

Commit

Permalink
perf: I. AM. SPEED.
Browse files Browse the repository at this point in the history
0.04s per package
  • Loading branch information
adamperkowski committed Nov 18, 2024
1 parent c4006af commit 6933f8c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 18 deletions.
51 changes: 51 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**<br>depends on internet speed |
| `nvrs` | ~ 0.04s | **API requests included**<br>depends on internet speed |
| `nvrs --cmp` | ~ 0.0008s | depends on disk speed |
| `nvrs --take` | ~ 0.001s | depends on disk speed |

Expand Down
40 changes: 23 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);
}
Expand Down

0 comments on commit 6933f8c

Please sign in to comment.