Skip to content

Commit e12b9e3

Browse files
committed
refactor(sqlite): Encode olm hashes with rmp instead of serde_json
… like everything else in the sqlite crypto store.
1 parent a225293 commit e12b9e3

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/matrix-sdk-sqlite/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ rmp-serde = "1.1.1"
3232
ruma = { workspace = true }
3333
rusqlite = { version = "0.28.0", features = ["bundled"] }
3434
serde = { workspace = true }
35-
serde_json = { workspace = true }
3635
thiserror = { workspace = true }
3736
tokio = { version = "1.24.2", default-features = false, features = ["sync", "fs"] }
3837
tracing = { workspace = true }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Hashes in the olm_hash table were initially stored as JSON, even though
2+
-- everything else is MessagePack. Alongside this migration, the encoding is
3+
-- updated.
4+
DELETE FROM "olm_hash";

crates/matrix-sdk-sqlite/src/crypto_store.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl SqliteCryptoStore {
179179
}
180180
}
181181

182-
const DATABASE_VERSION: u8 = 1;
182+
const DATABASE_VERSION: u8 = 2;
183183

184184
async fn run_migrations(conn: &SqliteConn) -> rusqlite::Result<()> {
185185
let kv_exists = conn
@@ -221,6 +221,13 @@ async fn run_migrations(conn: &SqliteConn) -> rusqlite::Result<()> {
221221
.await?;
222222
}
223223

224+
if version < 2 {
225+
conn.with_transaction(|txn| {
226+
txn.execute_batch(include_str!("../migrations/002_reset_olm_hash.sql"))
227+
})
228+
.await?;
229+
}
230+
224231
conn.set_kv("version", vec![DATABASE_VERSION]).await?;
225232

226233
Ok(())
@@ -682,7 +689,7 @@ impl CryptoStore for SqliteCryptoStore {
682689
}
683690

684691
for hash in &changes.message_hashes {
685-
let hash = serde_json::to_vec(hash).map_err(CryptoStoreError::from)?;
692+
let hash = rmp_serde::to_vec(hash).map_err(CryptoStoreError::backend)?;
686693
txn.add_olm_hash(&hash)?;
687694
}
688695

@@ -906,7 +913,7 @@ impl CryptoStore for SqliteCryptoStore {
906913
&self,
907914
message_hash: &matrix_sdk_crypto::olm::OlmMessageHash,
908915
) -> StoreResult<bool> {
909-
let value = serde_json::to_vec(message_hash)?;
916+
let value = rmp_serde::to_vec(message_hash).map_err(CryptoStoreError::backend)?;
910917
Ok(self.acquire().await?.has_olm_hash(value).await?)
911918
}
912919

0 commit comments

Comments
 (0)