diff --git a/src/chat.rs b/src/chat.rs index 849b349a5..c448a2111 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -29,7 +29,6 @@ use crate::dc_tools::{ use crate::ephemeral::Timer as EphemeralTimer; use crate::events::EventType; use crate::html::new_html_mimepart; -use crate::job::{self, Action}; use crate::message::{self, Message, MessageState, MsgId, Viewtype}; use crate::mimefactory::MimeFactory; use crate::mimeparser::SystemMessage; @@ -556,9 +555,8 @@ impl ChatId { chat_id: ChatId::new(0), }); - job::kill_action(context, Action::Housekeeping).await?; - let j = job::Job::new(Action::Housekeeping, 0, Params::new(), 10); - job::add(context, j).await?; + context.set_config(Config::LastHousekeeping, None).await?; + context.interrupt_inbox(InterruptInfo::new(false)).await; if chat.is_self_talk() { let mut msg = Message::new(Viewtype::Text); diff --git a/src/job.rs b/src/job.rs index 959331bc7..aacd34322 100644 --- a/src/job.rs +++ b/src/job.rs @@ -15,7 +15,6 @@ use crate::dc_tools::time; use crate::events::EventType; use crate::imap::Imap; use crate::location; -use crate::log::LogExt; use crate::message::{Message, MsgId}; use crate::mimefactory::MimeFactory; use crate::param::{Param, Params}; @@ -84,7 +83,6 @@ pub enum Action { Unknown = 0, // Jobs in the INBOX-thread, range from DC_IMAP_THREAD..DC_IMAP_THREAD+999 - Housekeeping = 105, // low priority ... FetchExistingMsgs = 110, // this is user initiated so it should have a fairly high priority @@ -119,7 +117,6 @@ impl From for Thread { match action { Unknown => Thread::Unknown, - Housekeeping => Thread::Imap, FetchExistingMsgs => Thread::Imap, ResyncFolders => Thread::Imap, UpdateRecentQuota => Thread::Imap, @@ -598,10 +595,6 @@ async fn perform_job_action( } Action::ResyncFolders => job.resync_folders(context, connection.inbox()).await, Action::FetchExistingMsgs => job.fetch_existing_msgs(context, connection.inbox()).await, - Action::Housekeeping => { - sql::housekeeping(context).await.ok_or_log(context); - Status::Finished(Ok(())) - } Action::UpdateRecentQuota => match context.update_recent_quota(connection.inbox()).await { Ok(status) => status, Err(err) => Status::Finished(Err(err)), @@ -666,8 +659,7 @@ pub async fn add(context: &Context, job: Job) -> Result<()> { if delay_seconds == 0 { match action { Action::Unknown => unreachable!(), - Action::Housekeeping - | Action::ResyncFolders + Action::ResyncFolders | Action::FetchExistingMsgs | Action::UpdateRecentQuota | Action::DownloadMsg => { @@ -683,18 +675,6 @@ pub async fn add(context: &Context, job: Job) -> Result<()> { Ok(()) } -async fn load_housekeeping_job(context: &Context) -> Result> { - let last_time = context.get_config_i64(Config::LastHousekeeping).await?; - - let next_time = last_time + (60 * 60 * 24); - if next_time <= time() { - kill_action(context, Action::Housekeeping).await?; - Ok(Some(Job::new(Action::Housekeeping, 0, Params::new(), 0))) - } else { - Ok(None) - } -} - /// Load jobs from the database. /// /// Load jobs for this "[Thread]", i.e. either load SMTP jobs or load @@ -781,14 +761,7 @@ LIMIT 1; Thread::Unknown => { bail!("unknown thread for job") } - Thread::Imap => { - if let Some(job) = job { - Ok(Some(job)) - } else { - Ok(load_housekeeping_job(context).await?) - } - } - Thread::Smtp => Ok(job), + Thread::Imap | Thread::Smtp => Ok(job), } } @@ -836,8 +809,7 @@ mod tests { &InterruptInfo::new(false), ) .await?; - // The housekeeping job should be loaded as we didn't run housekeeping in the last day: - assert_eq!(jobs.unwrap().action, Action::Housekeeping); + assert!(jobs.is_none()); insert_job(&t, 1, true).await; let jobs = load_next( diff --git a/src/message.rs b/src/message.rs index 58b07d53f..10794cc3c 100644 --- a/src/message.rs +++ b/src/message.rs @@ -23,7 +23,7 @@ use crate::download::DownloadState; use crate::ephemeral::{start_ephemeral_timers_msgids, Timer as EphemeralTimer}; use crate::events::EventType; use crate::imap::markseen_on_imap_table; -use crate::job::{self, Action}; +use crate::job; use crate::log::LogExt; use crate::mimeparser::{parse_message_id, FailureReport, SystemMessage}; use crate::param::{Param, Params}; @@ -1258,15 +1258,12 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> { chat_id: ChatId::new(0), msg_id: MsgId::new(0), }); - job::kill_action(context, Action::Housekeeping).await?; - job::add( - context, - job::Job::new(Action::Housekeeping, 0, Params::new(), 10), - ) - .await?; + + // Run housekeeping to delete unused blobs. + context.set_config(Config::LastHousekeeping, None).await?; } - // Interrupt Inbox loop to start message deletion. + // Interrupt Inbox loop to start message deletion and run housekeeping. context.interrupt_inbox(InterruptInfo::new(false)).await; Ok(()) } diff --git a/src/scheduler.rs b/src/scheduler.rs index f4d25b125..3bd6f1c73 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -8,11 +8,13 @@ use async_std::{ use crate::config::Config; use crate::context::Context; use crate::dc_tools::maybe_add_time_based_warnings; +use crate::dc_tools::time; use crate::ephemeral::{self, delete_expired_imap_messages}; use crate::imap::Imap; use crate::job::{self, Thread}; use crate::log::LogExt; use crate::smtp::{send_smtp_messages, Smtp}; +use crate::sql; use self::connectivity::ConnectivityStore; @@ -114,6 +116,19 @@ async fn inbox_loop(ctx: Context, started: Sender<()>, inbox_handlers: ImapConne maybe_add_time_based_warnings(&ctx).await; + match ctx.get_config_i64(Config::LastHousekeeping).await { + Ok(last_housekeeping_time) => { + let next_housekeeping_time = + last_housekeeping_time.saturating_add(60 * 60 * 24); + if next_housekeeping_time <= time() { + sql::housekeeping(&ctx).await.ok_or_log(&ctx); + } + } + Err(err) => { + warn!(ctx, "Failed to get last housekeeping time: {}", err); + } + }; + info = fetch_idle(&ctx, &mut connection, Config::ConfiguredInboxFolder).await; } }