Move prune_tombstones() to sql:: and call from housekeeping()

This commit is contained in:
Alexander Krotov
2020-03-24 22:51:58 +03:00
parent 25f8a735a9
commit 270d18a88a
2 changed files with 20 additions and 13 deletions

View File

@@ -8,7 +8,7 @@ use rusqlite::{Connection, OpenFlags, Statement, NO_PARAMS};
use thread_local_object::ThreadLocal;
use crate::chat::{update_device_icon, update_saved_messages_icon};
use crate::constants::ShowEmails;
use crate::constants::{ShowEmails, DC_CHAT_ID_TRASH};
use crate::context::Context;
use crate::dc_tools::*;
use crate::param::*;
@@ -1053,6 +1053,18 @@ pub fn get_rowid2_with_conn(
}
}
/// Removes from the database locally deleted messages that also don't
/// have a server UID.
fn prune_tombstones(context: &Context) -> Result<()> {
context.sql.execute(
"DELETE FROM msgs \
WHERE (chat_id = ? OR hidden) \
AND server_uid = 0",
params![DC_CHAT_ID_TRASH],
)?;
Ok(())
}
pub fn housekeeping(context: &Context) {
let mut files_in_use = HashSet::new();
let mut unreferenced_count = 0;
@@ -1165,6 +1177,13 @@ pub fn housekeeping(context: &Context) {
}
}
if let Err(err) = prune_tombstones(context) {
warn!(
context,
"Houskeeping: Cannot prune message tombstones: {}", err
);
}
info!(context, "Housekeeping done.",);
}