Skip to content

Commit e608898

Browse files
committedFeb 20, 2025
refact, reload peers
Signed-off-by: fufesou <[email protected]>
1 parent 0d7f746 commit e608898

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed
 

‎protos/message.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ message LoginRequest {
7878
oneof union {
7979
FileTransfer file_transfer = 7;
8080
PortForward port_forward = 8;
81-
ViewCamera view_camera = 9;
81+
ViewCamera view_camera = 15;
8282
}
8383
bool video_ack_required = 9;
8484
uint64 session_id = 10;

‎src/config.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -1273,14 +1273,11 @@ impl PeerConfig {
12731273
Config::with_extension(Config::path(path))
12741274
}
12751275

1276-
#[inline]
12771276
// The number of peers to load in the first round when showing the peers card list in the main window.
12781277
// When there're too many peers, loading all of them at once will take a long time.
12791278
// We can load them in two rouds, the first round loads the first 100 peers, and the second round loads the rest.
12801279
// Then the UI will show the first 100 peers first, and the rest will be loaded and shown later.
1281-
pub fn get_loading_batch_count() -> usize {
1282-
100
1283-
}
1280+
pub const BATCH_LOADING_COUNT: usize = 100;
12841281

12851282
pub fn get_vec_id_modified_time_path(
12861283
id_filters: &Option<Vec<String>>,
@@ -1344,12 +1341,11 @@ impl PeerConfig {
13441341
async fn preload_peers_async() {
13451342
let now = std::time::Instant::now();
13461343
let vec_id_modified_time_path = Self::get_vec_id_modified_time_path(&None);
1347-
let batch_count = 300;
13481344
let total_count = vec_id_modified_time_path.len();
13491345
let mut futs = vec![];
13501346
for (_, _, path) in vec_id_modified_time_path.into_iter() {
13511347
futs.push(Self::preload_file_async(path));
1352-
if futs.len() >= batch_count {
1348+
if futs.len() >= Self::BATCH_LOADING_COUNT {
13531349
futures::future::join_all(futs).await;
13541350
futs = vec![];
13551351
}
@@ -1360,7 +1356,7 @@ impl PeerConfig {
13601356
log::info!(
13611357
"Preload peers done in {:?}, batch_count: {}, total: {}",
13621358
now.elapsed(),
1363-
batch_count,
1359+
Self::BATCH_LOADING_COUNT,
13641360
total_count
13651361
);
13661362
}
@@ -1397,11 +1393,13 @@ impl PeerConfig {
13971393

13981394
let to = match to {
13991395
Some(to) => to.min(all.len()),
1400-
None => {
1401-
let batch_count = Self::get_loading_batch_count();
1402-
(from + batch_count).min(all.len())
1403-
}
1396+
None => (from + Self::BATCH_LOADING_COUNT).min(all.len()),
14041397
};
1398+
1399+
// to <= from is unexpected, but we can just return an empty vec in this case.
1400+
if to <= from {
1401+
return (vec![], from);
1402+
}
14051403

14061404
let peers: Vec<_> = all[from..to]
14071405
.iter()

0 commit comments

Comments
 (0)
Please sign in to comment.