@@ -1273,14 +1273,11 @@ impl PeerConfig {
1273
1273
Config :: with_extension ( Config :: path ( path) )
1274
1274
}
1275
1275
1276
- #[ inline]
1277
1276
// The number of peers to load in the first round when showing the peers card list in the main window.
1278
1277
// When there're too many peers, loading all of them at once will take a long time.
1279
1278
// We can load them in two rouds, the first round loads the first 100 peers, and the second round loads the rest.
1280
1279
// 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 ;
1284
1281
1285
1282
pub fn get_vec_id_modified_time_path (
1286
1283
id_filters : & Option < Vec < String > > ,
@@ -1344,12 +1341,11 @@ impl PeerConfig {
1344
1341
async fn preload_peers_async ( ) {
1345
1342
let now = std:: time:: Instant :: now ( ) ;
1346
1343
let vec_id_modified_time_path = Self :: get_vec_id_modified_time_path ( & None ) ;
1347
- let batch_count = 300 ;
1348
1344
let total_count = vec_id_modified_time_path. len ( ) ;
1349
1345
let mut futs = vec ! [ ] ;
1350
1346
for ( _, _, path) in vec_id_modified_time_path. into_iter ( ) {
1351
1347
futs. push ( Self :: preload_file_async ( path) ) ;
1352
- if futs. len ( ) >= batch_count {
1348
+ if futs. len ( ) >= Self :: BATCH_LOADING_COUNT {
1353
1349
futures:: future:: join_all ( futs) . await ;
1354
1350
futs = vec ! [ ] ;
1355
1351
}
@@ -1360,7 +1356,7 @@ impl PeerConfig {
1360
1356
log:: info!(
1361
1357
"Preload peers done in {:?}, batch_count: {}, total: {}" ,
1362
1358
now. elapsed( ) ,
1363
- batch_count ,
1359
+ Self :: BATCH_LOADING_COUNT ,
1364
1360
total_count
1365
1361
) ;
1366
1362
}
@@ -1397,11 +1393,13 @@ impl PeerConfig {
1397
1393
1398
1394
let to = match to {
1399
1395
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 ( ) ) ,
1404
1397
} ;
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
+ }
1405
1403
1406
1404
let peers: Vec < _ > = all[ from..to]
1407
1405
. iter ( )
0 commit comments