Skip to content

Commit 3f3ddab

Browse files
committed
Support checkpoints without bucket priorities
1 parent 2ce69aa commit 3f3ddab

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

core/src/commonMain/kotlin/com/powersync/bucket/BucketChecksum.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable
66
@Serializable
77
internal data class BucketChecksum(
88
val bucket: String,
9-
val priority: BucketPriority,
9+
val priority: BucketPriority = BucketPriority.DEFAULT_PRIORITY,
1010
val checksum: Int,
1111
val count: Int? = null,
1212
@SerialName("last_op_id") val lastOpId: String? = null,

core/src/commonMain/kotlin/com/powersync/bucket/BucketPriority.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ public value class BucketPriority(private val priorityCode: Int): Comparable<Buc
1616

1717
public companion object {
1818
internal val FULL_SYNC_PRIORITY: BucketPriority = BucketPriority(Int.MAX_VALUE)
19+
20+
/**
21+
* The assumed priority for buckets when talking to older sync service instances that don't
22+
* support bucket priorities.
23+
*/
24+
internal val DEFAULT_PRIORITY: BucketPriority = BucketPriority(3)
1925
}
2026
}

core/src/commonTest/kotlin/com/powersync/sync/SyncLineTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.powersync.sync
22

3+
import com.powersync.bucket.BucketChecksum
34
import com.powersync.bucket.BucketPriority
45
import com.powersync.bucket.Checkpoint
56
import com.powersync.utils.JsonUtil
@@ -19,6 +20,22 @@ class SyncLineTest {
1920
)), """{"checkpoint": {"last_op_id": "10", "buckets": []}}""")
2021
}
2122

23+
@Test
24+
fun testDeserializeCheckpointNoPriority() {
25+
checkDeserializing(SyncLine.FullCheckpoint(Checkpoint(
26+
lastOpId = "10",
27+
checksums = listOf(BucketChecksum(bucket = "a", priority = BucketPriority(3), checksum = 10)),
28+
)), """{"checkpoint": {"last_op_id": "10", "buckets": [{"bucket": "a", "checksum": 10}]}}""")
29+
}
30+
31+
@Test
32+
fun testDeserializeCheckpointWithPriority() {
33+
checkDeserializing(SyncLine.FullCheckpoint(Checkpoint(
34+
lastOpId = "10",
35+
checksums = listOf(BucketChecksum(bucket = "a", priority = BucketPriority(1), checksum = 10)),
36+
)), """{"checkpoint": {"last_op_id": "10", "buckets": [{"bucket": "a", "priority": 1, "checksum": 10}]}}""")
37+
}
38+
2239
@Test
2340
fun testDeserializeCheckpointDiff() {
2441
checkDeserializing(SyncLine.CheckpointDiff(

0 commit comments

Comments
 (0)