Skip to content

Commit 36d8f28

Browse files
committed
Remove unused compaction logic
1 parent 7590cc5 commit 36d8f28

File tree

4 files changed

+5
-63
lines changed

4 files changed

+5
-63
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/common': patch
3+
---
4+
5+
Remove unused compaction logic.

packages/common/src/client/sync/bucket/BucketStorageAdapter.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,6 @@ export interface BucketStorageAdapter extends BaseObserver<BucketStorageListener
9696

9797
hasCompletedSync(): Promise<boolean>;
9898
updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
99-
/**
100-
* Exposed for tests only.
101-
*/
102-
autoCompact(): Promise<void>;
103-
104-
/**
105-
* Exposed for tests only.
106-
*/
107-
forceCompact(): Promise<void>;
108-
10999
getMaxOpId(): string;
110100

111101
/**

packages/common/src/client/sync/bucket/SqliteBucketStorage.ts

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,19 @@ import { CrudBatch } from './CrudBatch.js';
1818
import { CrudEntry, CrudEntryJSON } from './CrudEntry.js';
1919
import { SyncDataBatch } from './SyncDataBatch.js';
2020

21-
const COMPACT_OPERATION_INTERVAL = 1_000;
22-
2321
export 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)",

packages/web/tests/bucket_storage.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,6 @@ describe('Bucket Storage', { sequential: true }, () => {
514514
buckets: [{ bucket: 'bucket1', checksum: 7, priority: 3 }]
515515
});
516516

517-
await bucketStorage.forceCompact();
518-
519517
await syncLocalChecked({
520518
last_op_id: '4',
521519
write_checkpoint: '4',

0 commit comments

Comments
 (0)