Skip to content

Commit

Permalink
Use write-ahead-logging for sqlite database (#373)
Browse files Browse the repository at this point in the history
More information here: https://www.sqlite.org/wal.html

This is a feature of sqlite intended to allow for situations where higher concurrency is needed. We can see if it fixes #368 (comment), but it's a good practice regardless.

Tested on Android emulator
  • Loading branch information
richardhuaaa authored Dec 14, 2023
1 parent 792f22b commit e43f2d4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions bindings_ffi/examples/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class MainActivity : AppCompatActivity() {
val privateKey: ByteArray = SecureRandom().generateSeed(32)
val credentials: Credentials = Credentials.create(ECKeyPair.create(privateKey))
val inboxOwner = Web3jInboxOwner(credentials)
val dbPath: String = this.filesDir.absolutePath + "/android_example.db3"
val dbDir: File = File(this.filesDir.absolutePath, "xmtp_db")
dbDir.mkdir()
val dbPath: String = dbDir.absolutePath + "/android_example.db3"
val dbEncryptionKey: List<UByte> = SecureRandom().generateSeed(32).asUByteArray().asList()
Log.i(
"App",
Expand All @@ -70,6 +72,6 @@ class MainActivity : AppCompatActivity() {
}
}

File(dbPath).delete()
dbDir.deleteRecursively()
}
}
Binary file modified bindings_ffi/jniLibs/arm64-v8a/libuniffi_xmtpv3.so
Binary file not shown.
4 changes: 3 additions & 1 deletion xmtp_mls/src/storage/encrypted_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ impl EncryptedMessageStore {
}

fn init_db(&mut self) -> Result<(), StorageError> {
log::info!("Running DB migrations");
let conn = &mut self.raw_conn()?;
conn.batch_execute("PRAGMA journal_mode = WAL;")
.map_err(|e| StorageError::DbInit(e.to_string()))?;

log::info!("Running DB migrations");
conn.run_pending_migrations(MIGRATIONS)
.map_err(|e| StorageError::DbInit(e.to_string()))?;

Expand Down

0 comments on commit e43f2d4

Please sign in to comment.