mirror of
https://github.com/chatmail/core.git
synced 2026-04-29 03:16:29 +03:00
feat: mutex to prevent fetching from multiple IMAP servers at the same time
This commit is contained in:
@@ -242,6 +242,14 @@ pub struct InnerContext {
|
|||||||
/// Mutex to prevent running housekeeping from multiple threads at once.
|
/// Mutex to prevent running housekeeping from multiple threads at once.
|
||||||
pub(crate) housekeeping_mutex: Mutex<()>,
|
pub(crate) housekeeping_mutex: Mutex<()>,
|
||||||
|
|
||||||
|
/// Mutex to prevent multiple IMAP loops from fetching the messages at once.
|
||||||
|
///
|
||||||
|
/// Without this mutex IMAP loops may waste traffic downloading the same message
|
||||||
|
/// from multiple IMAP servers and create multiple copies of the same message
|
||||||
|
/// in the database if the check for duplicates and creating a message
|
||||||
|
/// happens in separate database transactions.
|
||||||
|
pub(crate) fetch_msgs_mutex: Mutex<()>,
|
||||||
|
|
||||||
pub(crate) translated_stockstrings: StockStrings,
|
pub(crate) translated_stockstrings: StockStrings,
|
||||||
pub(crate) events: Events,
|
pub(crate) events: Events,
|
||||||
|
|
||||||
@@ -482,6 +490,7 @@ impl Context {
|
|||||||
oauth2_mutex: Mutex::new(()),
|
oauth2_mutex: Mutex::new(()),
|
||||||
wrong_pw_warning_mutex: Mutex::new(()),
|
wrong_pw_warning_mutex: Mutex::new(()),
|
||||||
housekeeping_mutex: Mutex::new(()),
|
housekeeping_mutex: Mutex::new(()),
|
||||||
|
fetch_msgs_mutex: Mutex::new(()),
|
||||||
translated_stockstrings: stockstrings,
|
translated_stockstrings: stockstrings,
|
||||||
events,
|
events,
|
||||||
scheduler: SchedulerState::new(),
|
scheduler: SchedulerState::new(),
|
||||||
|
|||||||
@@ -606,6 +606,7 @@ impl Imap {
|
|||||||
.await
|
.await
|
||||||
.context("prefetch")?;
|
.context("prefetch")?;
|
||||||
let read_cnt = msgs.len();
|
let read_cnt = msgs.len();
|
||||||
|
let _fetch_msgs_lock_guard = context.fetch_msgs_mutex.lock().await;
|
||||||
|
|
||||||
let mut uids_fetch: Vec<u32> = Vec::new();
|
let mut uids_fetch: Vec<u32> = Vec::new();
|
||||||
let mut available_post_msgs: Vec<String> = Vec::new();
|
let mut available_post_msgs: Vec<String> = Vec::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user