@@ -7,6 +7,9 @@ use rla::index::IndexStorage;
7
7
use std:: collections:: { HashSet , VecDeque } ;
8
8
use std:: hash:: Hash ;
9
9
use std:: str;
10
+ use std:: time:: { Instant , Duration } ;
11
+
12
+ const MINIMUM_DELAY_BETWEEN_INDEX_BACKUPS : Duration = Duration :: from_secs ( 60 * 60 ) ;
10
13
11
14
pub struct Worker {
12
15
debug_post : Option < ( String , u32 ) > ,
@@ -22,6 +25,8 @@ pub struct Worker {
22
25
23
26
recently_notified : RecentlySeen < u64 > ,
24
27
recently_learned : RecentlySeen < String > ,
28
+
29
+ last_index_backup : Option < Instant > ,
25
30
}
26
31
27
32
impl Worker {
@@ -61,6 +66,8 @@ impl Worker {
61
66
62
67
recently_notified : RecentlySeen :: new ( 32 ) ,
63
68
recently_learned : RecentlySeen :: new ( 256 ) ,
69
+
70
+ last_index_backup : None ,
64
71
} )
65
72
}
66
73
@@ -322,7 +329,16 @@ impl Worker {
322
329
}
323
330
}
324
331
325
- self . index . save ( & self . index_file ) ?;
332
+ // To avoid persisting the index too many times to storage, we only persist it after some
333
+ // time elapsed since the last save.
334
+ match self . last_index_backup {
335
+ Some ( last) if last. elapsed ( ) >= MINIMUM_DELAY_BETWEEN_INDEX_BACKUPS => {
336
+ self . index . save ( & self . index_file ) ?;
337
+ self . last_index_backup = Some ( Instant :: now ( ) ) ;
338
+ }
339
+ Some ( _) => { }
340
+ None => self . last_index_backup = Some ( Instant :: now ( ) ) ,
341
+ }
326
342
327
343
Ok ( ( ) )
328
344
}
0 commit comments