Format
This commit is contained in:
parent
f19656486a
commit
07e1ab0796
3 changed files with 9 additions and 8 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -2,3 +2,5 @@
|
|||
*.db*
|
||||
/result
|
||||
*~
|
||||
#*
|
||||
#*#
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ pub fn merge_volume_scans(
|
|||
let mut index: HashMap<String, (Vec<String>, i64)> = HashMap::new();
|
||||
for (vol_url, keys) in scans {
|
||||
for (key, size) in keys {
|
||||
let entry = index.entry(key.clone()).or_insert_with(|| (Vec::new(), *size));
|
||||
let entry = index
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| (Vec::new(), *size));
|
||||
entry.0.push(vol_url.clone());
|
||||
if *size > entry.1 {
|
||||
entry.1 = *size;
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ pub fn first_healthy_volume(key: &str, volumes: &[String], results: &[bool]) ->
|
|||
}
|
||||
|
||||
pub fn shuffle_volumes(volumes: Vec<String>, seed: u64) -> Vec<String> {
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::SeedableRng;
|
||||
use rand::seq::SliceRandom;
|
||||
let mut rng = rand::rngs::StdRng::seed_from_u64(seed);
|
||||
let mut vols = volumes;
|
||||
vols.shuffle(&mut rng);
|
||||
|
|
@ -77,11 +77,9 @@ pub async fn get_key(
|
|||
}
|
||||
|
||||
match first_healthy_volume(&key, &volumes, &results) {
|
||||
ProbeResult::Found(url) => Ok((
|
||||
StatusCode::FOUND,
|
||||
[(axum::http::header::LOCATION, url)],
|
||||
)
|
||||
.into_response()),
|
||||
ProbeResult::Found(url) => {
|
||||
Ok((StatusCode::FOUND, [(axum::http::header::LOCATION, url)]).into_response())
|
||||
}
|
||||
ProbeResult::AllFailed => Err(AppError::AllVolumesUnreachable),
|
||||
}
|
||||
}
|
||||
|
|
@ -233,4 +231,3 @@ pub async fn list_keys(
|
|||
let keys = state.db.list_keys(&query.prefix).await?;
|
||||
Ok((StatusCode::OK, keys.join("\n")).into_response())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue