Skip to content

Commit bee9f5b

Browse files
authored
Do not strip transactions when uploading data
1 parent 5f32d69 commit bee9f5b

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ internal interface BucketStorage {
1414

1515
fun nextCrudItem(transaction: PowerSyncTransaction): CrudEntry?
1616

17+
fun getCrudItemsByTransactionId(
18+
transactionId: Int,
19+
transaction: PowerSyncTransaction,
20+
): List<CrudEntry>
21+
1722
suspend fun hasCrud(): Boolean
1823

1924
fun hasCrud(transaction: PowerSyncTransaction): Boolean

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,24 @@ internal class BucketStorageImpl(
4141
return id ?: throw IllegalStateException("Client ID not found")
4242
}
4343

44-
override suspend fun nextCrudItem(): CrudEntry? = db.getOptional(sql = nextCrudQuery, mapper = nextCrudMapper)
44+
override suspend fun nextCrudItem(): CrudEntry? = db.getOptional(sql = nextCrudQuery, mapper = crudEntryMapper)
4545

4646
override fun nextCrudItem(transaction: PowerSyncTransaction): CrudEntry? =
47-
transaction.getOptional(sql = nextCrudQuery, mapper = nextCrudMapper)
47+
transaction.getOptional(sql = nextCrudQuery, mapper = crudEntryMapper)
48+
49+
override fun fun getCrudItemsByTransactionId(
50+
transactionId: Int,
51+
transaction: PowerSyncTransaction,
52+
): List<CrudEntry> =
53+
transaction.getAll(
54+
sql = transactionCrudQuery,
55+
parameters = listOf(transactionId),
56+
mapper = crudEntryMapper,
57+
)
4858

4959
private val nextCrudQuery = "SELECT id, tx_id, data FROM ${InternalTable.CRUD} ORDER BY id ASC LIMIT 1"
50-
private val nextCrudMapper: (SqlCursor) -> CrudEntry = { cursor ->
60+
private val transactionCrudQuery = "SELECT id, tx_id, data FROM ${InternalTable.CRUD} WHERE tx_id = ? ORDER BY id ASC"
61+
private val crudEntryMapper: (SqlCursor) -> CrudEntry = { cursor ->
5162
CrudEntry.fromRow(
5263
CrudRow(
5364
id = cursor.getString(0)!!,

core/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,10 @@ internal class PowerSyncDatabaseImpl(
298298
if (txId == null) {
299299
listOf(entry)
300300
} else {
301-
transaction.getAll("SELECT id, tx_id, data FROM ps_crud ORDER BY id ASC LIMIT 1") {
302-
CrudEntry.fromRow(
303-
CrudRow(
304-
id = it.getString("id"),
305-
data = it.getString("data"),
306-
txId = it.getLongOptional("tx_id")?.toInt(),
307-
),
308-
)
309-
}
301+
bucketStorage.getCrudItemsByTransactionId(
302+
transactionId = txId,
303+
transaction = transaction,
304+
)
310305
}
311306

312307
return@readTransaction CrudTransaction(

0 commit comments

Comments
 (0)