From 141107c678dc47a4e7119cf9fd067bdb4f3e615f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 23 Jun 2020 16:42:27 +0200 Subject: [PATCH 1/3] electron-main: Skip the reindex if we're going to delete the db anyways. --- src/electron-main.js | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/electron-main.js b/src/electron-main.js index b68dfe5..03dac06 100644 --- a/src/electron-main.js +++ b/src/electron-main.js @@ -207,6 +207,14 @@ let eventIndex = null; let mainWindow = null; global.appQuitting = false; + +const deleteFolderRecursive = async (p) => { + for (const entry of await afs.readdir(p)) { + const curPath = path.join(p, entry); + await afs.unlink(curPath); + } +}; + // handle uncaught errors otherwise it displays // stack traces in popup dialogs, which is terrible (which // it will do any time the auto update poke fails, and there's @@ -453,7 +461,22 @@ ipcMain.on('seshat', async function(ev, payload) { const recoveryIndex = new SeshatRecovery(eventStorePath, { passphrase: seshatPassphrase, }); - await recoveryIndex.reindex(); + + const userVersion = await recoveryIndex.getUserVersion(); + + // If our user version is 0 we'll delete the db + // anyways so reindexing it is a waste of time. + if (userVersion === 0) { + await recoveryIndex.shutdown(); + + try { + await deleteFolderRecursive(eventStorePath); + } catch (e) { + } + } else { + await recoveryIndex.reindex(); + } + eventIndex = new Seshat(eventStorePath, { passphrase: seshatPassphrase, }); @@ -485,13 +508,6 @@ ipcMain.on('seshat', async function(ev, payload) { case 'deleteEventIndex': { - const deleteFolderRecursive = async (p) => { - for (const entry of await afs.readdir(p)) { - const curPath = path.join(p, entry); - await afs.unlink(curPath); - } - }; - try { await deleteFolderRecursive(eventStorePath); } catch (e) { From 2da6bc6a1e190501937a26836559286935b76234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 24 Jun 2020 11:06:09 +0200 Subject: [PATCH 2/3] electron-main: Rename the deletion method for the index. --- src/electron-main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/electron-main.js b/src/electron-main.js index 03dac06..00215cb 100644 --- a/src/electron-main.js +++ b/src/electron-main.js @@ -208,7 +208,7 @@ let mainWindow = null; global.appQuitting = false; -const deleteFolderRecursive = async (p) => { +const deleteContents = async (p) => { for (const entry of await afs.readdir(p)) { const curPath = path.join(p, entry); await afs.unlink(curPath); @@ -470,7 +470,7 @@ ipcMain.on('seshat', async function(ev, payload) { await recoveryIndex.shutdown(); try { - await deleteFolderRecursive(eventStorePath); + await deleteContents(eventStorePath); } catch (e) { } } else { @@ -509,7 +509,7 @@ ipcMain.on('seshat', async function(ev, payload) { case 'deleteEventIndex': { try { - await deleteFolderRecursive(eventStorePath); + await deleteContents(eventStorePath); } catch (e) { } } From b23cc417e1bae69128195c4837126d648714e1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 24 Jun 2020 16:31:49 +0200 Subject: [PATCH 3/3] package.json: Bump the required Seshat version. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 75bf5b6..d1f979b 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "tar": "^6.0.1" }, "hakDependencies": { - "matrix-seshat": "^2.0.0", + "matrix-seshat": "^2.1.0", "keytar": "^5.6.0" }, "build": {