feat: add count

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2024-03-29 13:19:23 +01:00
parent aaa6d05b92
commit 188fca648a
Signed by: cafkafk
GPG key ID: 26C542FD97F965CE
2 changed files with 10 additions and 6 deletions

View file

@ -26,7 +26,6 @@ const DEFAULT_CACHE: &str = "cache.nixos.org";
#[tokio::main(flavor = "multi_thread")] #[tokio::main(flavor = "multi_thread")]
async fn main() -> io::Result<()> { async fn main() -> io::Result<()> {
console_subscriber::init();
let host_name: String; let host_name: String;
let cache_url: String; let cache_url: String;
@ -76,10 +75,14 @@ async fn main() -> io::Result<()> {
let binding = get_requisites(&host_name); let binding = get_requisites(&host_name);
let tasks = binding let lines = binding
.lines() .lines()
.map(|line| line.to_owned()) .map(|line| line.to_owned())
.collect::<Vec<_>>() .collect::<Vec<_>>();
let count = lines.len();
let tasks = lines
.into_iter() .into_iter()
.map(|hash| { .map(|hash| {
let client = client.clone(); let client = client.clone();
@ -97,7 +100,7 @@ async fn main() -> io::Result<()> {
.map(|result| result.unwrap()) .map(|result| result.unwrap())
.sum(); .sum();
println!("sum {:#?}", sum); println!("sum {:#?}/{}", sum, count);
Ok(()) Ok(())
} }

View file

@ -4,6 +4,8 @@ use async_recursion::async_recursion;
use reqwest::Client; use reqwest::Client;
use tokio::time::sleep; use tokio::time::sleep;
const MAX_SLIDE: u64 = 1000;
#[async_recursion] #[async_recursion]
pub async fn nar_exists(client: Client, domain: &str, hash: &str, slide: u64) -> usize { pub async fn nar_exists(client: Client, domain: &str, hash: &str, slide: u64) -> usize {
let response = client let response = client
@ -19,9 +21,8 @@ pub async fn nar_exists(client: Client, domain: &str, hash: &str, slide: u64) ->
// //
// Writng an actual sliding window seems kinda hard, // Writng an actual sliding window seems kinda hard,
// so we do this instead. // so we do this instead.
println!("blablabllb");
sleep(Duration::from_millis(slide)).await; sleep(Duration::from_millis(slide)).await;
nar_exists(client, domain, hash, slide * 2).await nar_exists(client, domain, hash, std::cmp::min(slide * 2, MAX_SLIDE)).await
} }
} }
} }