mirror of
https://github.com/GiriNeko/hbb_common.git
synced 2025-12-16 13:27:23 +00:00
refact: optimize, preload peers.
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
f94753bddb
commit
33487a0b14
1 changed files with 6 additions and 1 deletions
|
|
@ -1346,7 +1346,12 @@ impl PeerConfig {
|
||||||
for (_, _, path) in vec_id_modified_time_path.into_iter() {
|
for (_, _, path) in vec_id_modified_time_path.into_iter() {
|
||||||
futs.push(Self::preload_file_async(path));
|
futs.push(Self::preload_file_async(path));
|
||||||
if futs.len() >= Self::BATCH_LOADING_COUNT {
|
if futs.len() >= Self::BATCH_LOADING_COUNT {
|
||||||
|
let first_load_start = std::time::Instant::now();
|
||||||
futures::future::join_all(futs).await;
|
futures::future::join_all(futs).await;
|
||||||
|
if first_load_start.elapsed().as_millis() < 10 {
|
||||||
|
// No need to preload the rest if the first load is fast.
|
||||||
|
return;
|
||||||
|
}
|
||||||
futs = vec![];
|
futs = vec![];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue