Skip to content

Commit

Permalink
Restore fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Feb 7, 2024
1 parent c0c8998 commit 74902dc
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions src/index/sparse_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,23 @@ impl RemoteSparseIndex {
#[inline]
pub fn krates(
&self,
krates: BTreeSet<String>,
mut krates: BTreeSet<String>,
write_cache_entries: bool,
lock: &FileLock,
) -> BTreeMap<String, Result<Option<IndexKrate>, Error>> {
let Some(prep_krate) = krates.pop_last() else {
return Default::default();
};

let prep = || {
let name = prep_krate.as_str().try_into()?;
self.krate(name, write_cache_entries, lock)
};

let prep_krate_res = prep();

use rayon::prelude::*;
krates
let mut results: BTreeMap<_, _> = krates
.into_par_iter()
.map(|kname| {
let res = || {
Expand All @@ -89,7 +100,10 @@ impl RemoteSparseIndex {
let res = res();
(kname, res)
})
.collect()
.collect();

results.insert(prep_krate, prep_krate_res);
results
}
}

Expand Down Expand Up @@ -184,14 +198,44 @@ impl AsyncRemoteSparseIndex {
/// via something like [`tokio::time::timeout`](https://docs.rs/tokio/latest/tokio/time/fn.timeout.html)
pub async fn krates(
&self,
krates: BTreeSet<String>,
mut krates: BTreeSet<String>,
write_cache_entries: bool,
individual_timeout: Option<std::time::Duration>,
lock: &FileLock,
) -> BTreeMap<String, Result<Option<IndexKrate>, Error>> {
let mut tasks = tokio::task::JoinSet::new();
let Some(prep_krate) = krates.pop_last() else {
return Default::default();
};

let create_req = |kname: &str| -> Result<http::Request<&'static [u8]>, Error> {
let name = kname.try_into()?;
self.index.make_remote_request(name, None, lock)
};

let mut results = BTreeMap::new();

{
let result;
match create_req(&prep_krate).and_then(|req| Ok(req.try_into()?)) {
Ok(req) => match Self::exec_request(&self.client, req).await {
Ok(res) => {
result = self.index.parse_remote_response(
prep_krate.as_str().try_into().unwrap(),
res,
write_cache_entries,
lock,
);
}
Err(err) => result = Err(err),
},
Err(err) => result = Err(err),
}

results.insert(prep_krate, result);
}

let mut tasks = tokio::task::JoinSet::new();

for kname in krates {
match kname.as_str().try_into().and_then(|name| {
Ok(self
Expand Down

0 comments on commit 74902dc

Please sign in to comment.