Skip to content

Commit 0da750c

Browse files
committed
Fix bad merges
1 parent 9f6fec5 commit 0da750c

File tree

4 files changed

+73
-20
lines changed

4 files changed

+73
-20
lines changed

packages/powersync_core/lib/src/database/powersync_db_mixin.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,9 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
123123
Future<void> _updateHasSynced() async {
124124
// Query the database to see if any data has been synced.
125125
final result = await database.get('''
126-
SELECT CASE
127-
WHEN EXISTS (SELECT 1 FROM sqlite_master WHERE name = 'ps_sync_state')
128-
THEN (SELECT json_group_array(
129-
json_object('prio', priority, 'last_sync', last_synced_at)
130-
) FROM ps_sync_state ORDER BY priority)
131-
ELSE powersync_last_synced_at()
132-
END AS r;
126+
SELECT json_group_array(
127+
json_object('prio', priority, 'last_sync', last_synced_at)
128+
) AS r FROM ps_sync_state ORDER BY priority
133129
''');
134130
final value = result['r'] as String?;
135131
final hasData = value != null;

packages/powersync_core/lib/src/streaming_sync.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,6 @@ class StreamingSyncImplementation implements StreamingSync {
444444
hasSynced: true,
445445
));
446446
}
447-
448-
validatedCheckpoint = targetCheckpoint;
449447
case StreamingSyncCheckpointDiff():
450448
// TODO: It may be faster to just keep track of the diff, instead of
451449
// the entire checkpoint
@@ -479,12 +477,12 @@ class StreamingSyncImplementation implements StreamingSync {
479477
case SyncDataBatch():
480478
_updateStatus(downloading: true);
481479
await adapter.saveSyncData(line);
482-
case StreamingSyncKeepalive():
483-
if (line.tokenExpiresIn == 0) {
480+
case StreamingSyncKeepalive(:final tokenExpiresIn):
481+
if (tokenExpiresIn == 0) {
484482
// Token expired already - stop the connection immediately
485483
invalidCredentialsCallback?.call().ignore();
486484
break;
487-
} else if (line.tokenExpiresIn <= 30) {
485+
} else if (tokenExpiresIn <= 30) {
488486
// Token expires soon - refresh it in the background
489487
if (credentialsInvalidation == null &&
490488
invalidCredentialsCallback != null) {
@@ -501,8 +499,7 @@ class StreamingSyncImplementation implements StreamingSync {
501499
}
502500
}
503501
case UnknownSyncLine(:final rawData):
504-
isolateLogger.fine('Ignoring unknown sync line: $rawData');
505-
break;
502+
isolateLogger.fine('Unknown sync line: $rawData');
506503
case null: // Local ping
507504
if (targetCheckpoint == appliedCheckpoint) {
508505
_updateStatus(

packages/powersync_core/test/in_memory_sync_test.dart

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,66 @@ void main() {
102102
isTrue);
103103
});
104104

105+
test('can save independent buckets in same transaction', () async {
106+
final status = await waitForConnection();
107+
108+
syncService.addLine({
109+
'checkpoint': Checkpoint(
110+
lastOpId: '0',
111+
writeCheckpoint: null,
112+
checksums: [
113+
BucketChecksum(bucket: 'a', checksum: 0, priority: 3),
114+
BucketChecksum(bucket: 'b', checksum: 0, priority: 3),
115+
],
116+
)
117+
});
118+
await expectLater(status, emits(isSyncStatus(downloading: true)));
119+
120+
var commits = 0;
121+
raw.commits.listen((_) => commits++);
122+
123+
syncService
124+
..addLine({
125+
'data': {
126+
'bucket': 'a',
127+
'data': <Map<String, Object?>>[
128+
{
129+
'op_id': '1',
130+
'op': 'PUT',
131+
'object_type': 'a',
132+
'object_id': '1',
133+
'checksum': 0,
134+
'data': {},
135+
}
136+
],
137+
}
138+
})
139+
..addLine({
140+
'data': {
141+
'bucket': 'b',
142+
'data': <Map<String, Object?>>[
143+
{
144+
'op_id': '2',
145+
'op': 'PUT',
146+
'object_type': 'b',
147+
'object_id': '1',
148+
'checksum': 0,
149+
'data': {},
150+
}
151+
],
152+
}
153+
});
154+
155+
// Wait for the operations to be inserted.
156+
while (raw.select('SELECT * FROM ps_oplog;').length < 2) {
157+
await pumpEventQueue();
158+
}
159+
160+
// The two buckets should have been inserted in a single transaction
161+
// because the messages were received in quick succession.
162+
expect(commits, 1);
163+
});
164+
105165
group('partial sync', () {
106166
test('updates sync state incrementally', () async {
107167
final status = await waitForConnection();

packages/powersync_core/test/utils/native_test_utils.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ class TestOpenFactory extends PowerSyncOpenFactory with TestPowerSyncFactory {
2323
});
2424
}
2525

26+
@override
27+
CommonDatabase open(SqliteOpenOptions options) {
28+
applyOpenOverride();
29+
return super.open(options);
30+
}
31+
2632
@override
2733
void enableExtension() {
2834
var powersyncLib = getLibraryForPlatform();
2935
sqlite3.ensureExtensionLoaded(SqliteExtension.inLibrary(
3036
DynamicLibrary.open(powersyncLib), 'sqlite3_powersync_init'));
3137
}
3238

33-
@override
34-
CommonDatabase open(SqliteOpenOptions options) {
35-
applyOpenOverride();
36-
return super.open(options);
37-
}
38-
3939
@override
4040
String getLibraryForPlatform({String? path = "."}) {
4141
switch (Abi.current()) {

0 commit comments

Comments
 (0)