File tree Expand file tree Collapse file tree 6 files changed +42
-0
lines changed
Expand file tree Collapse file tree 6 files changed +42
-0
lines changed Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff line change @@ -78,3 +78,10 @@ export function getConfig<T = any>(
7878export 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+ }
Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff 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+
3341export async function reloadUICommand ( ) {
3442 await editor . reloadUI ( ) ;
3543}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments