diff --git a/CHANGELOG.md b/CHANGELOG.md index 42b69dbc2..0213cb803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Fix a problem with Gmail where (auto-)deleted messages would get archived instead of deleted. Move them to the Trash folder for Gmail which auto-deletes trashed messages in 30 days #3972 - Clear config cache after backup import. This bug sometimes resulted in the import to seemingly work at first. #4067 +- Update timestamps in `param` columns with transactions. #4083 ### API-Changes diff --git a/src/update_helper.rs b/src/update_helper.rs index 9136b23df..ed140dfdd 100644 --- a/src/update_helper.rs +++ b/src/update_helper.rs @@ -2,8 +2,8 @@ use anyhow::Result; -use crate::chat::{Chat, ChatId}; -use crate::contact::{Contact, ContactId}; +use crate::chat::ChatId; +use crate::contact::ContactId; use crate::context::Context; use crate::param::{Param, Params}; @@ -17,12 +17,26 @@ impl Context { scope: Param, new_timestamp: i64, ) -> Result { - let mut contact = Contact::load_from_db(self, contact_id).await?; - if contact.param.update_timestamp(scope, new_timestamp)? { - contact.update_param(self).await?; - return Ok(true); - } - Ok(false) + self.sql + .transaction(|transaction| { + let mut param: Params = transaction.query_row( + "SELECT param FROM contacts WHERE id=?", + [contact_id], + |row| { + let param: String = row.get(0)?; + Ok(param.parse().unwrap_or_default()) + }, + )?; + let update = param.update_timestamp(scope, new_timestamp)?; + if update { + transaction.execute( + "UPDATE contacts SET param=? WHERE id=?", + params![param.to_string(), contact_id], + )?; + } + Ok(update) + }) + .await } } @@ -35,12 +49,24 @@ impl ChatId { scope: Param, new_timestamp: i64, ) -> Result { - let mut chat = Chat::load_from_db(context, *self).await?; - if chat.param.update_timestamp(scope, new_timestamp)? { - chat.update_param(context).await?; - return Ok(true); - } - Ok(false) + context + .sql + .transaction(|transaction| { + let mut param: Params = + transaction.query_row("SELECT param FROM chats WHERE id=?", [self], |row| { + let param: String = row.get(0)?; + Ok(param.parse().unwrap_or_default()) + })?; + let update = param.update_timestamp(scope, new_timestamp)?; + if update { + transaction.execute( + "UPDATE chats SET param=? WHERE id=?", + params![param.to_string(), self], + )?; + } + Ok(update) + }) + .await } } @@ -60,6 +86,7 @@ impl Params { #[cfg(test)] mod tests { use super::*; + use crate::chat::Chat; use crate::receive_imf::receive_imf; use crate::test_utils::TestContext; use crate::tools::time;