Delete orphan txs after accounts are deleted concurrently with sync

This commit is contained in:
Hanh 2023-03-01 13:50:28 +10:00
parent 9830a34ec4
commit 12aa5328ab
1 changed files with 7 additions and 0 deletions

View File

@ -166,6 +166,7 @@ impl DbAdapter {
pub fn init_db(&mut self) -> anyhow::Result<()> {
self.delete_incomplete_scan()?;
self.delete_orphan_transactions()?;
Ok(())
}
@ -1087,6 +1088,12 @@ impl DbAdapter {
Ok(())
}
pub fn delete_orphan_transactions(&self) -> anyhow::Result<()> {
self.connection.execute("DELETE FROM transactions WHERE id_tx IN (SELECT tx.id_tx FROM transactions tx LEFT JOIN accounts a ON tx.account = a.id_account WHERE a.id_account IS NULL)",
[])?;
Ok(())
}
pub fn store_message(&self, account: u32, message: &ZMessage) -> anyhow::Result<()> {
self.connection.execute("INSERT INTO messages(account, id_tx, sender, recipient, subject, body, timestamp, height, incoming, read) VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10)",
params![account, message.id_tx, message.sender, message.recipient, message.subject, message.body, message.timestamp, message.height, message.incoming, false])?;