Skip to content

Commit 9521e24

Browse files
DominicGBauerDominicGBauer
andauthored
chore(common): improve deleteBucket function (#268)
Co-authored-by: DominicGBauer <dominic@nomanini.com>
1 parent 05e3469 commit 9521e24

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
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+
Change internals of deleteBucket to use simpler action

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,12 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
103103
* Mark a bucket for deletion.
104104
*/
105105
private async deleteBucket(bucket: string) {
106-
// Delete a bucket, but allow it to be re-created.
107-
// To achieve this, we rename the bucket to a new temp name, and change all ops to remove.
108-
// By itself, this new bucket would ensure that the previous objects are deleted if they contain no more references.
109-
// If the old bucket is re-added, this new bucket would have no effect.
110106
await this.writeTransaction(async (tx) => {
111-
const { uuid } = await tx.get<{ uuid: string }>('select uuid() as uuid');
112-
const newName = `$delete_${bucket}_${uuid}`;
113-
this.logger.debug('Deleting bucket', bucket);
114107
await tx.execute(
115-
`UPDATE ps_oplog SET op=${OpTypeEnum.REMOVE}, data=NULL WHERE op=${OpTypeEnum.PUT} AND superseded=0 AND bucket=?`,
116-
[bucket]
117-
);
118-
// Rename bucket
119-
await tx.execute('UPDATE ps_oplog SET bucket=? WHERE bucket=?', [newName, bucket]);
120-
await tx.execute('DELETE FROM ps_buckets WHERE name = ?', [bucket]);
121-
await tx.execute(
122-
'INSERT INTO ps_buckets(name, pending_delete, last_op) SELECT ?, 1, IFNULL(MAX(op_id), 0) FROM ps_oplog WHERE bucket = ?',
123-
[newName, newName]
124-
);
108+
'INSERT INTO powersync_operations(op, data) VALUES(?, ?)',
109+
['delete_bucket', bucket]);
125110
});
111+
126112
this.logger.debug('done deleting bucket');
127113
this.pendingBucketDeletes = true;
128114
}

0 commit comments

Comments
 (0)