@@ -18,28 +18,19 @@ import { CrudBatch } from './CrudBatch.js';
1818import { CrudEntry , CrudEntryJSON } from './CrudEntry.js' ;
1919import { SyncDataBatch } from './SyncDataBatch.js' ;
2020
21- const COMPACT_OPERATION_INTERVAL = 1_000 ;
22-
2321export class SqliteBucketStorage extends BaseObserver < BucketStorageListener > implements BucketStorageAdapter {
2422 public tableNames : Set < string > ;
25- private pendingBucketDeletes : boolean ;
2623 private _hasCompletedSync : boolean ;
2724 private updateListener : ( ) => void ;
2825 private _clientId ?: Promise < string > ;
2926
30- /**
31- * Count up, and do a compact on startup.
32- */
33- private compactCounter = COMPACT_OPERATION_INTERVAL ;
34-
3527 constructor (
3628 private db : DBAdapter ,
3729 private mutex : Mutex ,
3830 private logger : ILogger = Logger . get ( 'SqliteBucketStorage' )
3931 ) {
4032 super ( ) ;
4133 this . _hasCompletedSync = false ;
42- this . pendingBucketDeletes = true ;
4334 this . tableNames = new Set ( ) ;
4435 this . updateListener = db . registerListener ( {
4536 tablesUpdated : ( update ) => {
@@ -102,16 +93,13 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
10293
10394 async saveSyncData ( batch : SyncDataBatch , fixedKeyFormat : boolean = false ) {
10495 await this . writeTransaction ( async ( tx ) => {
105- let count = 0 ;
10696 for ( const b of batch . buckets ) {
10797 const result = await tx . execute ( 'INSERT INTO powersync_operations(op, data) VALUES(?, ?)' , [
10898 'save' ,
10999 JSON . stringify ( { buckets : [ b . toJSON ( fixedKeyFormat ) ] } )
110100 ] ) ;
111101 this . logger . debug ( 'saveSyncData' , JSON . stringify ( result ) ) ;
112- count += b . data . length ;
113102 }
114- this . compactCounter += count ;
115103 } ) ;
116104 }
117105
@@ -130,7 +118,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
130118 } ) ;
131119
132120 this . logger . debug ( 'done deleting bucket' ) ;
133- this . pendingBucketDeletes = true ;
134121 }
135122
136123 async hasCompletedSync ( ) {
@@ -177,8 +164,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
177164 return { ready : false , checkpointValid : true } ;
178165 }
179166
180- await this . forceCompact ( ) ;
181-
182167 return {
183168 ready : true ,
184169 checkpointValid : true
@@ -260,42 +245,6 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
260245 }
261246 }
262247
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-
299248 async updateLocalTarget ( cb : ( ) => Promise < string > ) : Promise < boolean > {
300249 const rs1 = await this . db . getAll (
301250 "SELECT target_op FROM ps_buckets WHERE name = '$local' AND target_op = CAST(? as INTEGER)" ,
0 commit comments