mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
Automatically delete messages in 2 weeks window only
This is to avoid creating thousands of jobs when user enables "delete_server_after" setting for the first time. If device is offline for more than 2 weeks, some messages may not be deleted.
This commit is contained in:
14
src/job.rs
14
src/job.rs
@@ -943,15 +943,25 @@ fn add_imap_deletion_jobs(context: &Context) -> sql::Result<()> {
|
|||||||
if let Some(delete_server_after) = context.get_config_delete_server_after() {
|
if let Some(delete_server_after) = context.get_config_delete_server_after() {
|
||||||
let threshold_timestamp = time() - delete_server_after;
|
let threshold_timestamp = time() - delete_server_after;
|
||||||
|
|
||||||
|
// Only try to delete messages in 2 weeks window
|
||||||
|
// (oldest_timestamp, threshold_timestamp). Otherwise we may
|
||||||
|
// waste a lot of traffic attempting to delete all the
|
||||||
|
// messages since the beginning of Delta Chat usage.
|
||||||
|
let oldest_timestamp = threshold_timestamp - 2 * 7 * 24 * 60 * 60;
|
||||||
|
|
||||||
// Select all expired messages which don't have a
|
// Select all expired messages which don't have a
|
||||||
// corresponding message deletion job yet.
|
// corresponding message deletion job yet.
|
||||||
let msg_ids = context.sql.query_map(
|
let msg_ids = context.sql.query_map(
|
||||||
"SELECT id FROM msgs
|
"SELECT id FROM msgs
|
||||||
WHERE timestamp < ?
|
WHERE timestamp < ? AND timestamp > ?
|
||||||
AND server_uid != 0
|
AND server_uid != 0
|
||||||
AND NOT EXISTS (SELECT 1 FROM jobs WHERE foreign_id = msgs.id
|
AND NOT EXISTS (SELECT 1 FROM jobs WHERE foreign_id = msgs.id
|
||||||
AND action = ?)",
|
AND action = ?)",
|
||||||
params![threshold_timestamp, Action::DeleteMsgOnImap],
|
params![
|
||||||
|
threshold_timestamp,
|
||||||
|
oldest_timestamp,
|
||||||
|
Action::DeleteMsgOnImap
|
||||||
|
],
|
||||||
|row| row.get::<_, MsgId>(0),
|
|row| row.get::<_, MsgId>(0),
|
||||||
|ids| {
|
|ids| {
|
||||||
ids.collect::<std::result::Result<Vec<_>, _>>()
|
ids.collect::<std::result::Result<Vec<_>, _>>()
|
||||||
|
|||||||
Reference in New Issue
Block a user