diff --git a/.changeset/healthy-carrots-exercise.md b/.changeset/healthy-carrots-exercise.md new file mode 100644 index 000000000..2c9dd66a2 --- /dev/null +++ b/.changeset/healthy-carrots-exercise.md @@ -0,0 +1,5 @@ +--- +'@powersync/common': patch +--- + +Remove unused compaction logic. diff --git a/packages/common/src/client/sync/bucket/BucketStorageAdapter.ts b/packages/common/src/client/sync/bucket/BucketStorageAdapter.ts index 76e92e4f3..3d6080769 100644 --- a/packages/common/src/client/sync/bucket/BucketStorageAdapter.ts +++ b/packages/common/src/client/sync/bucket/BucketStorageAdapter.ts @@ -96,16 +96,6 @@ export interface BucketStorageAdapter extends BaseObserver; updateLocalTarget(cb: () => Promise): Promise; - /** - * Exposed for tests only. - */ - autoCompact(): Promise; - - /** - * Exposed for tests only. - */ - forceCompact(): Promise; - getMaxOpId(): string; /** diff --git a/packages/common/src/client/sync/bucket/SqliteBucketStorage.ts b/packages/common/src/client/sync/bucket/SqliteBucketStorage.ts index a2bd3014f..c206e9fa2 100644 --- a/packages/common/src/client/sync/bucket/SqliteBucketStorage.ts +++ b/packages/common/src/client/sync/bucket/SqliteBucketStorage.ts @@ -18,20 +18,12 @@ import { CrudBatch } from './CrudBatch.js'; import { CrudEntry, CrudEntryJSON } from './CrudEntry.js'; import { SyncDataBatch } from './SyncDataBatch.js'; -const COMPACT_OPERATION_INTERVAL = 1_000; - export class SqliteBucketStorage extends BaseObserver implements BucketStorageAdapter { public tableNames: Set; - private pendingBucketDeletes: boolean; private _hasCompletedSync: boolean; private updateListener: () => void; private _clientId?: Promise; - /** - * Count up, and do a compact on startup. - */ - private compactCounter = COMPACT_OPERATION_INTERVAL; - constructor( private db: DBAdapter, private mutex: Mutex, @@ -39,7 +31,6 @@ export class SqliteBucketStorage extends BaseObserver imp ) { super(); this._hasCompletedSync = false; - this.pendingBucketDeletes = true; this.tableNames = new Set(); this.updateListener = db.registerListener({ tablesUpdated: (update) => { @@ -102,16 +93,13 @@ export class SqliteBucketStorage extends BaseObserver imp async saveSyncData(batch: SyncDataBatch, fixedKeyFormat: boolean = false) { await this.writeTransaction(async (tx) => { - let count = 0; for (const b of batch.buckets) { const result = await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', [ 'save', JSON.stringify({ buckets: [b.toJSON(fixedKeyFormat)] }) ]); this.logger.debug('saveSyncData', JSON.stringify(result)); - count += b.data.length; } - this.compactCounter += count; }); } @@ -130,7 +118,6 @@ export class SqliteBucketStorage extends BaseObserver imp }); this.logger.debug('done deleting bucket'); - this.pendingBucketDeletes = true; } async hasCompletedSync() { @@ -177,8 +164,6 @@ export class SqliteBucketStorage extends BaseObserver imp return { ready: false, checkpointValid: true }; } - await this.forceCompact(); - return { ready: true, checkpointValid: true @@ -260,42 +245,6 @@ export class SqliteBucketStorage extends BaseObserver imp } } - /** - * Force a compact, for tests. - */ - async forceCompact() { - this.compactCounter = COMPACT_OPERATION_INTERVAL; - this.pendingBucketDeletes = true; - - await this.autoCompact(); - } - - async autoCompact() { - await this.deletePendingBuckets(); - await this.clearRemoveOps(); - } - - private async deletePendingBuckets() { - if (this.pendingBucketDeletes !== false) { - await this.writeTransaction(async (tx) => { - await tx.execute('INSERT INTO powersync_operations(op, data) VALUES (?, ?)', ['delete_pending_buckets', '']); - }); - // Executed once after start-up, and again when there are pending deletes. - this.pendingBucketDeletes = false; - } - } - - private async clearRemoveOps() { - if (this.compactCounter < COMPACT_OPERATION_INTERVAL) { - return; - } - - await this.writeTransaction(async (tx) => { - await tx.execute('INSERT INTO powersync_operations(op, data) VALUES (?, ?)', ['clear_remove_ops', '']); - }); - this.compactCounter = 0; - } - async updateLocalTarget(cb: () => Promise): Promise { const rs1 = await this.db.getAll( "SELECT target_op FROM ps_buckets WHERE name = '$local' AND target_op = CAST(? as INTEGER)", diff --git a/packages/web/tests/bucket_storage.test.ts b/packages/web/tests/bucket_storage.test.ts index 70f9e6a10..66cce87e9 100644 --- a/packages/web/tests/bucket_storage.test.ts +++ b/packages/web/tests/bucket_storage.test.ts @@ -514,8 +514,6 @@ describe('Bucket Storage', { sequential: true }, () => { buckets: [{ bucket: 'bucket1', checksum: 7, priority: 3 }] }); - await bucketStorage.forceCompact(); - await syncLocalChecked({ last_op_id: '4', write_checkpoint: '4',