Modern Apps git

← Modern-Apps.git

library: fix Room live UI refresh by disabling WAL in SQLCipher helper

Commit
7dd738667f936af8bbb85e4825495d7f7ad5e0d4
Author
Vayun Mathur <[email protected]>
When
2026-08-14 04:45 UTC (3 months ago)
Parents
e7e120d

Diff

library/room/src/main/java/com/vayunmathur/library/room/SqlCipher.kt
diff --git a/library/room/src/main/java/com/vayunmathur/library/room/SqlCipher.kt b/library/room/src/main/java/com/vayunmathur/library/room/SqlCipher.ktindex ea8765453e..9b03087766 100644--- a/library/room/src/main/java/com/vayunmathur/library/room/SqlCipher.kt+++ b/library/room/src/main/java/com/vayunmathur/library/room/SqlCipher.kt@@ -84,6 +84,15 @@ inline fun <reified T : RoomDatabase> Context.buildDatabase(          builder.openHelperFactory(SupportOpenHelperFactory(password.toByteArray(Charsets.UTF_8))) +        // Force TRUNCATE (rollback-journal) mode instead of the default WAL. With the+        // net.zetetic SQLCipher SupportSQLiteOpenHelper, WAL breaks Room's+        // InvalidationTracker: a write marks the table dirty but the change+        // notification isn't dispatched until a *later* write forces a refresh, so+        // Flow-backed queries only update on the next unrelated DB write (observed as+        // list UIs lagging until the next background write). TRUNCATE restores prompt,+        // per-write invalidation for every RoomDatabase built through this helper.+        builder.setJournalMode(RoomDatabase.JournalMode.TRUNCATE)+         val db = builder.build()         databases[T::class] = db         return db