notes: bump updatedAt on batch local writes
- Commit
2ca314c7ed06b05c9ca25ef33ee079b67ea5141b- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 20:10 UTC (29 days ago)
- Parents
aa41f94
Symptom: reordering notes in the list looked saved but never reached other devices, and a later sync pull could silently restore the old order locally. Root cause: the reorder path persists through NotesViewModel.upsertAll -> NotesRepository.upsertAll -> NoteDao.upsertAll, which was a raw @Upsert that kept the stored updatedAt. Relay sync only ships rows from getUpdatedSince, so a position-only change was invisible to it. The single-note upsert path already bumps updatedAt for exactly this reason. Fix: NoteDao.upsertAll is now a local batch write that bumps updatedAt per row (delegating to upsertAllRaw, which relay sync keeps for verbatim pulled rows). Legacy import in MainActivity uses the same path and is also a local write, so it gets the bump too. Verification: new NotesRepositoryTest case asserts a position-only upsertAll bumps updatedAt and appears in getUpdatedSince. Full notes unit-test suite run at the end of this stack.
Diff
notes/src/main/java/com/vayunmathur/notes/data/NoteDatabase.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/data/NoteDatabase.kt b/notes/src/main/java/com/vayunmathur/notes/data/NoteDatabase.ktindex 2ac2c500ea..c7777dfdbd 100644--- a/notes/src/main/java/com/vayunmathur/notes/data/NoteDatabase.kt+++ b/notes/src/main/java/com/vayunmathur/notes/data/NoteDatabase.kt@@ -56,8 +56,9 @@ abstract class NoteDao { @Query("DELETE FROM Note") abstract suspend fun deleteAll() - @Upsert- abstract suspend fun upsertAll(t: List<Note>)+ /** Local batch write (list reorder, legacy import): bumps updatedAt like [upsert]. */+ suspend fun upsertAll(values: List<Note>) =+ upsertAllRaw(values.map { it.copy(updatedAt = System.currentTimeMillis()) }) /** Writes [values] verbatim. Only the relay sync uses this. */ @Upsert
notes/src/test/java/com/vayunmathur/notes/data/NotesRepositoryTest.kt
diff --git a/notes/src/test/java/com/vayunmathur/notes/data/NotesRepositoryTest.kt b/notes/src/test/java/com/vayunmathur/notes/data/NotesRepositoryTest.ktindex 584d7c9545..24e5d18085 100644--- a/notes/src/test/java/com/vayunmathur/notes/data/NotesRepositoryTest.kt+++ b/notes/src/test/java/com/vayunmathur/notes/data/NotesRepositoryTest.kt@@ -80,6 +80,16 @@ class NotesRepositoryTest { assertTrue(repo.getAllSnapshots().isEmpty()) } + @Test fun upsertAllBumpsUpdatedAtSoReorderSyncs() = runTest {+ repo.upsertRaw(Note(title = "A", content = "", syncId = "ord-a", updatedAt = 10, position = 1.0))+ val stored = repo.getBySyncId("ord-a")!!+ repo.upsertAll(listOf(stored.copy(position = 99.0)))+ val after = repo.getBySyncId("ord-a")!!+ assertEquals(99.0, after.position)+ assertTrue(after.updatedAt > 10, "reorder must bump updatedAt or sync never sees it: ${after.updatedAt}")+ assertEquals(listOf("ord-a"), repo.getUpdatedSince(100).map { it.syncId })+ }+ @Test fun migrateImageReferencesRewritesOnlyImageBlocks() = runTest { val body = NoteBody(listOf( NoteBlock.Text("caption", "t1"),