@@ -18,28 +18,19 @@ import { CrudBatch } from './CrudBatch.js';
18
18
import { CrudEntry , CrudEntryJSON } from './CrudEntry.js' ;
19
19
import { SyncDataBatch } from './SyncDataBatch.js' ;
20
20
21
- const COMPACT_OPERATION_INTERVAL = 1_000 ;
22
-
23
21
export class SqliteBucketStorage extends BaseObserver < BucketStorageListener > implements BucketStorageAdapter {
24
22
public tableNames : Set < string > ;
25
- private pendingBucketDeletes : boolean ;
26
23
private _hasCompletedSync : boolean ;
27
24
private updateListener : ( ) => void ;
28
25
private _clientId ?: Promise < string > ;
29
26
30
- /**
31
- * Count up, and do a compact on startup.
32
- */
33
- private compactCounter = COMPACT_OPERATION_INTERVAL ;
34
-
35
27
constructor (
36
28
private db : DBAdapter ,
37
29
private mutex : Mutex ,
38
30
private logger : ILogger = Logger . get ( 'SqliteBucketStorage' )
39
31
) {
40
32
super ( ) ;
41
33
this . _hasCompletedSync = false ;
42
- this . pendingBucketDeletes = true ;
43
34
this . tableNames = new Set ( ) ;
44
35
this . updateListener = db . registerListener ( {
45
36
tablesUpdated : ( update ) => {
@@ -102,16 +93,13 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
102
93
103
94
async saveSyncData ( batch : SyncDataBatch , fixedKeyFormat : boolean = false ) {
104
95
await this . writeTransaction ( async ( tx ) => {
105
- let count = 0 ;
106
96
for ( const b of batch . buckets ) {
107
97
const result = await tx . execute ( 'INSERT INTO powersync_operations(op, data) VALUES(?, ?)' , [
108
98
'save' ,
109
99
JSON . stringify ( { buckets : [ b . toJSON ( fixedKeyFormat ) ] } )
110
100
] ) ;
111
101
this . logger . debug ( 'saveSyncData' , JSON . stringify ( result ) ) ;
112
- count += b . data . length ;
113
102
}
114
- this . compactCounter += count ;
115
103
} ) ;
116
104
}
117
105
@@ -130,7 +118,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
130
118
} ) ;
131
119
132
120
this . logger . debug ( 'done deleting bucket' ) ;
133
- this . pendingBucketDeletes = true ;
134
121
}
135
122
136
123
async hasCompletedSync ( ) {
@@ -177,8 +164,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
177
164
return { ready : false , checkpointValid : true } ;
178
165
}
179
166
180
- await this . forceCompact ( ) ;
181
-
182
167
return {
183
168
ready : true ,
184
169
checkpointValid : true
@@ -260,42 +245,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
260
245
}
261
246
}
262
247
263
- /**
264
- * Force a compact, for tests.
265
- */
266
- async forceCompact ( ) {
267
- this . compactCounter = COMPACT_OPERATION_INTERVAL ;
268
- this . pendingBucketDeletes = true ;
269
-
270
- await this . autoCompact ( ) ;
271
- }
272
-
273
- async autoCompact ( ) {
274
- await this . deletePendingBuckets ( ) ;
275
- await this . clearRemoveOps ( ) ;
276
- }
277
-
278
- private async deletePendingBuckets ( ) {
279
- if ( this . pendingBucketDeletes !== false ) {
280
- await this . writeTransaction ( async ( tx ) => {
281
- await tx . execute ( 'INSERT INTO powersync_operations(op, data) VALUES (?, ?)' , [ 'delete_pending_buckets' , '' ] ) ;
282
- } ) ;
283
- // Executed once after start-up, and again when there are pending deletes.
284
- this . pendingBucketDeletes = false ;
285
- }
286
- }
287
-
288
- private async clearRemoveOps ( ) {
289
- if ( this . compactCounter < COMPACT_OPERATION_INTERVAL ) {
290
- return ;
291
- }
292
-
293
- await this . writeTransaction ( async ( tx ) => {
294
- await tx . execute ( 'INSERT INTO powersync_operations(op, data) VALUES (?, ?)' , [ 'clear_remove_ops' , '' ] ) ;
295
- } ) ;
296
- this . compactCounter = 0 ;
297
- }
298
-
299
248
async updateLocalTarget ( cb : ( ) => Promise < string > ) : Promise < boolean > {
300
249
const rs1 = await this . db . getAll (
301
250
"SELECT target_op FROM ps_buckets WHERE name = '$local' AND target_op = CAST(? as INTEGER)" ,
0 commit comments