Skip to content

Commit 5bbb535

Browse files
fix legacy offline uploads
1 parent b45e02f commit 5bbb535

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 1.5.1 (unreleased)
4+
5+
* Fix issue in legacy sync client where local writes made offline could have their upload delayed
6+
until a keepalive event was received. This could also cause downloaded updates to be delayed even
7+
further until all uploads were
8+
completed.
9+
310
## 1.5.0
411

512
* Add `PowerSyncDatabase.getCrudTransactions()`, returning a flow of transactions. This is useful

core/src/commonIntegrationTest/kotlin/com/powersync/sync/SyncIntegrationTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ abstract class BaseSyncIntegrationTest(
612612
database.watch("SELECT name FROM users") { it.getString(0)!! }.testIn(scope)
613613
query.awaitItem() shouldBe listOf("local write")
614614

615-
syncLines.send(SyncLine.KeepAlive(tokenExpiresIn = 1234))
616615
syncLines.send(
617616
SyncLine.FullCheckpoint(
618617
Checkpoint(

core/src/commonMain/kotlin/com/powersync/sync/SyncStream.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,20 @@ internal class SyncStream(
536536
lateinit var receiveLines: Job
537537
receiveLines =
538538
scope.launch {
539+
var hadLine = false
539540
receiveTextLines(JsonUtil.json.encodeToJsonElement(req)).collect { value ->
540541
val line = JsonUtil.json.decodeFromString<SyncLine>(value)
541542

543+
if (!hadLine) {
544+
// Trigger a crud upload when receiving the first sync line: We could have
545+
// pending local writes made while disconnected, so in addition to listening on
546+
// updates to `ps_crud`, we also need to trigger a CRUD upload in some other
547+
// cases. We do this on the first sync line because the client is likely to be
548+
// online in that case.
549+
hadLine = true
550+
triggerCrudUploadAsync()
551+
}
552+
542553
state = handleInstruction(line, value, state)
543554

544555
if (state.abortIteration) {

0 commit comments

Comments
 (0)