mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
add rate limit for quota check in background fetch (12h for now)
This commit is contained in:
@@ -214,6 +214,9 @@ pub(crate) const DC_FOLDERS_CONFIGURED_VERSION: i32 = 4;
|
|||||||
// `max_smtp_rcpt_to` in the provider db.
|
// `max_smtp_rcpt_to` in the provider db.
|
||||||
pub(crate) const DEFAULT_MAX_SMTP_RCPT_TO: usize = 50;
|
pub(crate) const DEFAULT_MAX_SMTP_RCPT_TO: usize = 50;
|
||||||
|
|
||||||
|
/// How far the last quota check needs to be in the past to be checked by the background function (in seconds).
|
||||||
|
pub(crate) const DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT: i64 = 12 * 60 * 60; // 12 hours
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use tokio::sync::{Mutex, Notify, RwLock};
|
|||||||
|
|
||||||
use crate::chat::{get_chat_cnt, ChatId};
|
use crate::chat::{get_chat_cnt, ChatId};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::constants::DC_VERSION_STR;
|
use crate::constants::{DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT, DC_VERSION_STR};
|
||||||
use crate::contact::Contact;
|
use crate::contact::Contact;
|
||||||
use crate::debug_logging::DebugLogging;
|
use crate::debug_logging::DebugLogging;
|
||||||
use crate::events::{Event, EventEmitter, EventType, Events};
|
use crate::events::{Event, EventEmitter, EventType, Events};
|
||||||
@@ -466,9 +466,19 @@ impl Context {
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update quota (to send warning if full)
|
// update quota (to send warning if full) - but only check it once in a while
|
||||||
if let Err(err) = self.update_recent_quota(&mut connection).await {
|
let quota_needs_update = {
|
||||||
warn!(self, "Failed to update quota: {err:#}.");
|
let quota = self.quota.read().await;
|
||||||
|
quota
|
||||||
|
.as_ref()
|
||||||
|
.filter(|quota| quota.modified + DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT > time())
|
||||||
|
.is_none()
|
||||||
|
};
|
||||||
|
|
||||||
|
if quota_needs_update {
|
||||||
|
if let Err(err) = self.update_recent_quota(&mut connection).await {
|
||||||
|
warn!(self, "Failed to update quota: {err:#}.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
|
|||||||
Reference in New Issue
Block a user