mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Update timestamps in parameters with transactions
This avoids accidentally reverting the changes to the `param` column done by another thread.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
- Fix a problem with Gmail where (auto-)deleted messages would get archived instead of deleted.
|
- 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
|
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
|
- 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
|
### API-Changes
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use crate::chat::{Chat, ChatId};
|
use crate::chat::ChatId;
|
||||||
use crate::contact::{Contact, ContactId};
|
use crate::contact::ContactId;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::param::{Param, Params};
|
use crate::param::{Param, Params};
|
||||||
|
|
||||||
@@ -17,12 +17,26 @@ impl Context {
|
|||||||
scope: Param,
|
scope: Param,
|
||||||
new_timestamp: i64,
|
new_timestamp: i64,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let mut contact = Contact::load_from_db(self, contact_id).await?;
|
self.sql
|
||||||
if contact.param.update_timestamp(scope, new_timestamp)? {
|
.transaction(|transaction| {
|
||||||
contact.update_param(self).await?;
|
let mut param: Params = transaction.query_row(
|
||||||
return Ok(true);
|
"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(false)
|
Ok(update)
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,12 +49,24 @@ impl ChatId {
|
|||||||
scope: Param,
|
scope: Param,
|
||||||
new_timestamp: i64,
|
new_timestamp: i64,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let mut chat = Chat::load_from_db(context, *self).await?;
|
context
|
||||||
if chat.param.update_timestamp(scope, new_timestamp)? {
|
.sql
|
||||||
chat.update_param(context).await?;
|
.transaction(|transaction| {
|
||||||
return Ok(true);
|
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(false)
|
Ok(update)
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +86,7 @@ impl Params {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::chat::Chat;
|
||||||
use crate::receive_imf::receive_imf;
|
use crate::receive_imf::receive_imf;
|
||||||
use crate::test_utils::TestContext;
|
use crate::test_utils::TestContext;
|
||||||
use crate::tools::time;
|
use crate::tools::time;
|
||||||
|
|||||||
Reference in New Issue
Block a user