Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electron-main: Skip the reindex if we're going to delete the db anyways. #104

Merged
merged 3 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"tar": "^6.0.1"
},
"hakDependencies": {
"matrix-seshat": "^2.0.0",
"matrix-seshat": "^2.1.0",
"keytar": "^5.6.0"
},
"build": {
Expand Down
34 changes: 25 additions & 9 deletions src/electron-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ let eventIndex = null;
let mainWindow = null;
global.appQuitting = false;


const deleteContents = 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
Expand Down Expand Up @@ -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 deleteContents(eventStorePath);
} catch (e) {
}
} else {
await recoveryIndex.reindex();
}

eventIndex = new Seshat(eventStorePath, {
passphrase: seshatPassphrase,
});
Expand Down Expand Up @@ -485,15 +508,8 @@ 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);
await deleteContents(eventStorePath);
} catch (e) {
}
}
Expand Down