Skip to content

Commit 18bea2e

Browse files
committed
Client: Clean command
1 parent 272f293 commit 18bea2e

File tree

6 files changed

+42
-0
lines changed

6 files changed

+42
-0
lines changed

client/data/encrypted_kv_primitives.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export class EncryptedKvPrimitives implements KvPrimitives {
2222
this.keyKey = encryptionKey;
2323
}
2424

25+
get dbName(): string {
26+
return (this.wrapped as any).dbName;
27+
}
28+
2529
// MUST immediately be called after constructor
2630
async init() {
2731
this.dataKey = await deriveGCMKeyFromCTR(this.keyKey);

client/plugos/syscalls/system.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ export function systemSyscalls(
108108
alert("Client wiped, feel free to navigate elsewhere");
109109
}
110110
},
111+
"system.cleanDatabases": async (): Promise<boolean> => {
112+
// Determine current dbName
113+
const dbName = (client.ds.kv as any).dbName;
114+
const suffix = dbName.replace("sb_data", "");
115+
if (indexedDB.databases) {
116+
const allDbs = await indexedDB.databases();
117+
for (const db of allDbs) {
118+
if (!db.name?.endsWith(suffix)) {
119+
console.log("Deleting database", db.name);
120+
indexedDB.deleteDatabase(db.name!);
121+
}
122+
}
123+
return true;
124+
} else {
125+
return false;
126+
}
127+
},
111128
// DEPRECATED
112129
"system.getEnv": () => {
113130
console.warn(

plug-api/syscalls/system.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ export function getConfig<T = any>(
7878
export function wipeClient(logout = false): Promise<void> {
7979
return syscall("system.wipeClient", logout);
8080
}
81+
82+
/**
83+
* Deletes all IndexedDB databases that are not connected to client (e.g. legacy databases)
84+
*/
85+
export function cleanDatabases(): Promise<boolean> {
86+
return syscall("system.cleanDatabases");
87+
}

plugs/editor/editor.plug.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ functions:
256256
command:
257257
name: "Client: Wipe"
258258

259+
cleanClientCommand:
260+
path: ./system.ts:cleanClientCommand
261+
command:
262+
name: "Client: Clean"
263+
259264
wipeAndLogoutCommand:
260265
path: ./system.ts:wipeAndLogoutCommand
261266
command:

plugs/editor/system.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ export async function wipeAndLogoutCommand() {
3030
await system.wipeClient(true);
3131
}
3232

33+
export async function cleanClientCommand() {
34+
if (await system.cleanDatabases()) {
35+
await editor.alert("Successfullly cleaned unnecessary client databases.");
36+
} else {
37+
await editor.alert("Failed to clean unnecessary client databases.");
38+
}
39+
}
40+
3341
export async function reloadUICommand() {
3442
await editor.reloadUI();
3543
}

website/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ An attempt at documenting the changes/new features introduced in each release.
1616
* [Vimeo](https://github.com/silverbulletmd/silverbullet/pull/1616)
1717
* [Peertube](https://github.com/silverbulletmd/silverbullet/pull/1612)
1818
* Atomic upgrades with `silverbullet update` and `silverbullet update-edge` (by [Mihai Maruseac](https://github.com/silverbulletmd/silverbullet/pull/1634))
19+
* Added `Client : Clean` command that deletes all redundant IndexedDB databases (ones the client is not using)
1920
* Fix: bottom search bar dark mode styling (by [numan](https://github.com/silverbulletmd/silverbullet/pull/1614))
2021
* Fix: navigation with auto links (by [MrMugame](https://github.com/silverbulletmd/silverbullet/pull/1607))
2122

0 commit comments

Comments
 (0)