From 9eb672ea178ce0bdf86177cbdf22e9df2aae4607 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sun, 22 Mar 2020 07:59:43 +0300 Subject: [PATCH] Move removal of chat message tombstones to a separate function DELETE operation may be slow compared to UPDATE. It is better to do in a separate job. --- src/chat.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index d184e3ad2..ab3e9af98 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2521,18 +2521,22 @@ pub fn delete_device_expired_messages(context: &Context) -> sql::Result<()> { WHERE timestamp < ?", params![threshold_timestamp], )?; - - // Delete hidden messages that are removed from the server. - context.sql.execute( - "DELETE FROM msgs \ - WHERE (chat_id = ? OR hidden) \ - AND server_uid = 0", - params![DC_CHAT_ID_TRASH], - )?; } Ok(()) } +/// Removes from the database locally deleted messages that also don't +/// have a server UID. +pub fn prune_tombstones(context: &Context) -> sql::Result<()> { + context.sql.execute( + "DELETE FROM msgs \ + WHERE (chat_id = ? OR hidden) \ + AND server_uid = 0", + params![DC_CHAT_ID_TRASH], + )?; + Ok(()) +} + #[cfg(test)] mod tests { use super::*;