mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 02:16:29 +03:00
fix: reduce the scope of the last_full_folder_scan lock in scan_folders
This makes it easier to ensure that holding this lock does not result in deadlocks.
This commit is contained in:
@@ -17,16 +17,24 @@ impl Imap {
|
||||
session: &mut Session,
|
||||
) -> Result<bool> {
|
||||
// First of all, debounce to once per minute:
|
||||
let mut last_scan = context.last_full_folder_scan.lock().await;
|
||||
if let Some(last_scan) = *last_scan {
|
||||
let elapsed_secs = time_elapsed(&last_scan).as_secs();
|
||||
let debounce_secs = context
|
||||
.get_config_u64(Config::ScanAllFoldersDebounceSecs)
|
||||
.await?;
|
||||
{
|
||||
let mut last_scan = context.last_full_folder_scan.lock().await;
|
||||
if let Some(last_scan) = *last_scan {
|
||||
let elapsed_secs = time_elapsed(&last_scan).as_secs();
|
||||
let debounce_secs = context
|
||||
.get_config_u64(Config::ScanAllFoldersDebounceSecs)
|
||||
.await?;
|
||||
|
||||
if elapsed_secs < debounce_secs {
|
||||
return Ok(false);
|
||||
if elapsed_secs < debounce_secs {
|
||||
return Ok(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the timestamp before scanning the folders
|
||||
// to avoid holding the lock for too long.
|
||||
// This means next scan is delayed even if
|
||||
// the current one fails.
|
||||
last_scan.replace(tools::Time::now());
|
||||
}
|
||||
info!(context, "Starting full folder scan");
|
||||
|
||||
@@ -94,7 +102,6 @@ impl Imap {
|
||||
}
|
||||
|
||||
info!(context, "Found folders: {folder_names:?}.");
|
||||
last_scan.replace(tools::Time::now());
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user