crypto: Use an upsert for the account saving.
parent
c3654bd03f
commit
23065a5aa3
|
@ -225,9 +225,15 @@ impl CryptoStore for SqliteStore {
|
|||
let mut connection = self.connection.lock().await;
|
||||
|
||||
query(
|
||||
"INSERT OR IGNORE INTO accounts (
|
||||
"INSERT INTO accounts (
|
||||
user_id, device_id, pickle, shared
|
||||
) VALUES (?, ?, ?, ?)",
|
||||
) VALUES (?1, ?2, ?3, ?4)
|
||||
ON CONFLICT(user_id, device_id) DO UPDATE SET
|
||||
pickle = ?3,
|
||||
shared = ?4
|
||||
WHERE user_id = ?1 and
|
||||
device_id = ?2
|
||||
",
|
||||
)
|
||||
.bind(&*self.user_id)
|
||||
.bind(&*self.device_id)
|
||||
|
@ -236,20 +242,6 @@ impl CryptoStore for SqliteStore {
|
|||
.execute(&mut *connection)
|
||||
.await?;
|
||||
|
||||
query(
|
||||
"UPDATE accounts
|
||||
SET pickle = ?,
|
||||
shared = ?
|
||||
WHERE user_id = ? and
|
||||
device_id = ?",
|
||||
)
|
||||
.bind(pickle)
|
||||
.bind(acc.shared)
|
||||
.bind(&*self.user_id)
|
||||
.bind(&*self.device_id)
|
||||
.execute(&mut *connection)
|
||||
.await?;
|
||||
|
||||
let account_id: (i64,) =
|
||||
query_as("SELECT id FROM accounts WHERE user_id = ? and device_id = ?")
|
||||
.bind(&*self.user_id)
|
||||
|
|
Loading…
Reference in New Issue