@@ -17,16 +17,24 @@ impl Imap {
17
17
session : & mut Session ,
18
18
) -> Result < bool > {
19
19
// First of all, debounce to once per minute:
20
- let mut last_scan = context. last_full_folder_scan . lock ( ) . await ;
21
- if let Some ( last_scan) = * last_scan {
22
- let elapsed_secs = time_elapsed ( & last_scan) . as_secs ( ) ;
23
- let debounce_secs = context
24
- . get_config_u64 ( Config :: ScanAllFoldersDebounceSecs )
25
- . await ?;
20
+ {
21
+ let mut last_scan = context. last_full_folder_scan . lock ( ) . await ;
22
+ if let Some ( last_scan) = * last_scan {
23
+ let elapsed_secs = time_elapsed ( & last_scan) . as_secs ( ) ;
24
+ let debounce_secs = context
25
+ . get_config_u64 ( Config :: ScanAllFoldersDebounceSecs )
26
+ . await ?;
26
27
27
- if elapsed_secs < debounce_secs {
28
- return Ok ( false ) ;
28
+ if elapsed_secs < debounce_secs {
29
+ return Ok ( false ) ;
30
+ }
29
31
}
32
+
33
+ // Update the timestamp before scanning the folders
34
+ // to avoid holding the lock for too long.
35
+ // This means next scan is delayed even if
36
+ // the current one fails.
37
+ last_scan. replace ( tools:: Time :: now ( ) ) ;
30
38
}
31
39
info ! ( context, "Starting full folder scan" ) ;
32
40
@@ -94,7 +102,6 @@ impl Imap {
94
102
}
95
103
96
104
info ! ( context, "Found folders: {folder_names:?}." ) ;
97
- last_scan. replace ( tools:: Time :: now ( ) ) ;
98
105
Ok ( true )
99
106
}
100
107
}
0 commit comments