mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
Delete messages more thoroughly (and at all) (#2114)
- Make sure delete_expired_messages and housekeeping runs once a day - delete more info about messages when putting them to trash (esp. also delete txt_raw, from_id and to_id as we don't need those anymore, so they are data that was unnecessarily kept) fix #1926, fix #2090 Also: * Nicer test_utils: add send_text() and print_chat() * Adapt ephemeral messages for testing (make them accurate to the second) * Add test for ephemeral messages * Make pop_sent_msg() really pop the last sent message
This commit is contained in:
19
src/job.rs
19
src/job.rs
@@ -1215,6 +1215,18 @@ pub async fn add(context: &Context, job: Job) {
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_housekeeping_job(context: &Context) -> Option<Job> {
|
||||
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;
|
||||
Some(Job::new(Action::Housekeeping, 0, Params::new(), 0))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Load jobs from the database.
|
||||
///
|
||||
/// Load jobs for this "[Thread]", i.e. either load SMTP jobs or load
|
||||
@@ -1331,8 +1343,10 @@ LIMIT 1;
|
||||
} else {
|
||||
Some(job)
|
||||
}
|
||||
} else if let Some(job) = load_imap_deletion_job(context).await.unwrap_or_default() {
|
||||
Some(job)
|
||||
} else {
|
||||
load_imap_deletion_job(context).await.unwrap_or_default()
|
||||
load_housekeeping_job(context).await
|
||||
}
|
||||
}
|
||||
Thread::Smtp => job,
|
||||
@@ -1379,7 +1393,8 @@ mod tests {
|
||||
&InterruptInfo::new(false, None),
|
||||
)
|
||||
.await;
|
||||
assert!(jobs.is_none());
|
||||
// The housekeeping job should be loaded as we didn't run housekeeping in the last day:
|
||||
assert!(jobs.unwrap().action == Action::Housekeeping);
|
||||
|
||||
insert_job(&t, 1).await;
|
||||
let jobs = load_next(
|
||||
|
||||
Reference in New Issue
Block a user