Skip to content

Commit 53b29a9

Browse files
DominicGBauerDominicGBauer
andauthored
fix: handle null values in opData (#43)
* fix: handle null values in opData * chore: pr feedback --------- Co-authored-by: DominicGBauer <[email protected]>
1 parent 06451d5 commit 53b29a9

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ import com.powersync.sync.SyncDataBatch
77
import com.powersync.sync.SyncLocalDatabaseResult
88
import co.touchlab.stately.concurrency.AtomicBoolean
99
import kotlinx.serialization.encodeToString
10-
import com.benasher44.uuid.uuid4
1110
import com.powersync.db.internal.InternalTable
1211
import com.powersync.utils.JsonUtil
13-
import kotlinx.coroutines.runBlocking
1412

1513
internal class BucketStorage(
1614
private val db: PsInternalDatabase,
1715
private val logger: Logger
1816
) {
1917
private val tableNames: MutableSet<String> = mutableSetOf()
2018
private var hasCompletedSync = AtomicBoolean(false)
21-
private var checksumCache: ChecksumCache? = null
2219
private var pendingBucketDeletes = AtomicBoolean(false)
2320

2421
/**
@@ -200,7 +197,7 @@ internal class BucketStorage(
200197
)
201198
}
202199

203-
suspend fun validateChecksums(checkpoint: Checkpoint): SyncLocalDatabaseResult {
200+
private suspend fun validateChecksums(checkpoint: Checkpoint): SyncLocalDatabaseResult {
204201
val res = db.getOptional(
205202
"SELECT powersync_validate_checkpoint(?) as result",
206203
parameters = listOf(JsonUtil.json.encodeToString(checkpoint)),
@@ -232,7 +229,7 @@ internal class BucketStorage(
232229
}
233230
}
234231

235-
suspend fun forceCompact() {
232+
private suspend fun forceCompact() {
236233
// Reset counter
237234
this.compactCounter = COMPACT_OPERATION_INTERVAL
238235
this.pendingBucketDeletes.value = true
@@ -241,7 +238,7 @@ internal class BucketStorage(
241238
}
242239

243240

244-
suspend fun autoCompact() {
241+
private suspend fun autoCompact() {
245242
// 1. Delete buckets
246243
deletePendingBuckets()
247244

core/src/commonMain/kotlin/com/powersync/db/crud/CrudEntry.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.powersync.db.crud
22

33
import com.powersync.utils.JsonUtil
4+
import kotlinx.serialization.json.contentOrNull
45
import kotlinx.serialization.json.jsonObject
56
import kotlinx.serialization.json.jsonPrimitive
67

@@ -51,7 +52,7 @@ public data class CrudEntry(
5152
*
5253
* For DELETE, this is null.
5354
*/
54-
val opData: Map<String, String>?
55+
val opData: Map<String, String?>?
5556
) {
5657
public companion object {
5758
public fun fromRow(row: CrudRow): CrudEntry {
@@ -60,7 +61,9 @@ public data class CrudEntry(
6061
id = data["id"]!!.jsonPrimitive.content,
6162
clientId = row.id.toInt(),
6263
op = UpdateType.fromJsonChecked(data["op"]!!.jsonPrimitive.content),
63-
opData = data["data"]?.jsonObject?.mapValues { it.value.jsonPrimitive.content },
64+
opData = data["data"]?.jsonObject?.mapValues { (_, value) ->
65+
value.jsonPrimitive.contentOrNull
66+
},
6467
table = data["type"]!!.jsonPrimitive.content,
6568
transactionId = row.txId,
6669
)
@@ -71,4 +74,4 @@ public data class CrudEntry(
7174
return "CrudEntry<$transactionId/$clientId ${op.toJson()} $table/$id $opData>"
7275
}
7376

74-
}
77+
}

0 commit comments

Comments
 (0)