@@ -45,14 +45,6 @@ class BucketStorage {
45
45
return rows.first['client_id' ] as String ;
46
46
}
47
47
48
- Future <void > streamOp (String op) async {
49
- await writeTransaction ((tx) async {
50
- await tx.execute (
51
- 'INSERT INTO powersync_operations(op, data) VALUES(?, ?)' ,
52
- ['stream' , op]);
53
- });
54
- }
55
-
56
48
Future <void > saveSyncData (SyncDataBatch batch) async {
57
49
var count = 0 ;
58
50
@@ -65,7 +57,10 @@ class BucketStorage {
65
57
'buckets' : [b]
66
58
}));
67
59
}
68
- });
60
+ // No need to flush - the data is not directly visible to the user either way.
61
+ // We get major initial sync performance improvements with IndexedDB by
62
+ // not flushing here.
63
+ }, flush: false );
69
64
_compactCounter += count;
70
65
}
71
66
@@ -85,7 +80,8 @@ class BucketStorage {
85
80
await tx.execute (
86
81
'INSERT INTO powersync_operations(op, data) VALUES(?, ?)' ,
87
82
['delete_bucket' , bucket]);
88
- });
83
+ // No need to flush - not directly visible to the user
84
+ }, flush: false );
89
85
90
86
_pendingBucketDeletes = true ;
91
87
}
@@ -125,7 +121,8 @@ class BucketStorage {
125
121
"UPDATE ps_buckets SET last_op = ? WHERE name = '\$ local'" ,
126
122
[checkpoint.writeCheckpoint]);
127
123
}
128
- });
124
+ // Not flushing here - the flush will happen in the next step
125
+ }, flush: false );
129
126
130
127
final valid = await updateObjectsFromBuckets (checkpoint);
131
128
if (! valid) {
@@ -150,7 +147,10 @@ class BucketStorage {
150
147
// can_update_local(db) == false
151
148
return false ;
152
149
}
153
- });
150
+ // Important to flush here.
151
+ // After this step, the synced data will be visible to the user,
152
+ // and we don't want that to be reverted.
153
+ }, flush: true );
154
154
}
155
155
156
156
Future <SyncLocalDatabaseResult > validateChecksums (
@@ -176,39 +176,25 @@ class BucketStorage {
176
176
}
177
177
178
178
Future <void > autoCompact () async {
179
+ // This is a no-op since powersync-sqlite-core v0.3.0
180
+
179
181
// 1. Delete buckets
180
182
await _deletePendingBuckets ();
181
183
182
184
// 2. Clear REMOVE operations, only keeping PUT ones
183
185
await _clearRemoveOps ();
184
-
185
- // await _compactWal();
186
- }
187
-
188
- // ignore: unused_element
189
- Future <void > _compactWal () async {
190
- try {
191
- await writeTransaction ((tx) async {
192
- await tx.execute ('PRAGMA wal_checkpoint(TRUNCATE)' );
193
- });
194
- } on SqliteException catch (e) {
195
- // Ignore SQLITE_BUSY
196
- if (e.resultCode == 5 ) {
197
- // Ignore
198
- } else if (e.resultCode == 6 ) {
199
- // Ignore
200
- }
201
- }
202
186
}
203
187
204
188
Future <void > _deletePendingBuckets () async {
189
+ // This is a no-op since powersync-sqlite-core v0.3.0
205
190
if (_pendingBucketDeletes) {
206
191
// Executed once after start-up, and again when there are pending deletes.
207
192
await writeTransaction ((tx) async {
208
193
await tx.execute (
209
194
'INSERT INTO powersync_operations(op, data) VALUES (?, ?)' ,
210
195
['delete_pending_buckets' , '' ]);
211
- });
196
+ // No need to flush - not directly visible to the user
197
+ }, flush: false );
212
198
_pendingBucketDeletes = false ;
213
199
}
214
200
}
@@ -218,11 +204,13 @@ class BucketStorage {
218
204
return ;
219
205
}
220
206
207
+ // This is a no-op since powersync-sqlite-core v0.3.0
221
208
await writeTransaction ((tx) async {
222
209
await tx.execute (
223
210
'INSERT INTO powersync_operations(op, data) VALUES (?, ?)' ,
224
211
['clear_remove_ops' , '' ]);
225
- });
212
+ // No need to flush - not directly visible to the user
213
+ }, flush: false );
226
214
_compactCounter = 0 ;
227
215
}
228
216
@@ -267,7 +255,8 @@ class BucketStorage {
267
255
[opId]);
268
256
269
257
return true ;
270
- });
258
+ // Flush here - don't want to lose the write checkpoint updates.
259
+ }, flush: true );
271
260
}
272
261
273
262
Future <CrudEntry ?> nextCrudItem () async {
@@ -313,7 +302,8 @@ class BucketStorage {
313
302
await tx.execute (
314
303
'UPDATE ps_buckets SET target_op = $maxOpId WHERE name=\'\$ local\' ' );
315
304
}
316
- });
305
+ // Flush here - don't want to lose the write checkpoint updates.
306
+ }, flush: true );
317
307
});
318
308
}
319
309
@@ -323,7 +313,8 @@ class BucketStorage {
323
313
/// concurrently.
324
314
Future <T > writeTransaction <T >(
325
315
Future <T > Function (SqliteWriteContext tx) callback,
326
- {Duration ? lockTimeout}) async {
316
+ {Duration ? lockTimeout,
317
+ required bool flush}) async {
327
318
return _internalDb.writeTransaction (callback, lockTimeout: lockTimeout);
328
319
}
329
320
}
0 commit comments