Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: improve database deletion

Abdullah Atta8f569539150d
diff --git a/apps/web/__e2e__/models/utils.ts b/apps/web/__e2e__/models/utils.ts
index 0564862d7..90a0a8764 100644
--- a/apps/web/__e2e__/models/utils.ts
+++ b/apps/web/__e2e__/models/utils.ts
@@ -21,6 +21,7 @@ import { Reminder } from "@notesnook/core/dist/types";
import { Locator, Page } from "@playwright/test";
import { getTestId } from "../utils";
import { Item, Notebook } from "./types";
+import dayjs from "dayjs";
export async function* iterateList(list: Locator) {
const count = await list.count();
@@ -83,18 +84,10 @@ export async function fillReminderDialog(
if (reminder.date) {
const date = new Date(Date.now() + reminder.date);
if (reminder.mode === "once") {
- await dateInput.fill(
- `${date.getFullYear()}-${(date.getMonth() + 1)
- .toString()
- .padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`
- );
+ await dateInput.fill(dayjs(date).format("DD-MM-YYYY"));
}
- const time = `${date.getHours().toString().padStart(2, "0")}:${date
- .getMinutes()
- .toString()
- .padStart(2, "0")}`;
- await timeInput.fill(time);
+ await timeInput.fill(dayjs(date).format("hh:mm A"));
}
await confirmDialog(dialog);
@@ -112,7 +105,7 @@ export async function fillItemDialog(page: Page, item: Item) {
export async function fillPasswordDialog(page: Page, password: string) {
const dialog = page.locator(getTestId("password-dialog"));
- await dialog.locator(getTestId("dialog-password")).fill(password);
+ await dialog.locator(getTestId("password")).fill(password);
await confirmDialog(dialog);
}
diff --git a/apps/web/src/common/sqlite/AccessHandlePoolVFS.js b/apps/web/src/common/sqlite/AccessHandlePoolVFS.js
index 7344e7621..650bc4bd1 100644
--- a/apps/web/src/common/sqlite/AccessHandlePoolVFS.js
+++ b/apps/web/src/common/sqlite/AccessHandlePoolVFS.js
@@ -213,11 +213,7 @@ export class AccessHandlePoolVFS extends VFS.Base {
}
async delete() {
- console.log("CLSOGING");
- await this.close();
- console.log("CLSOGING", this.#directoryHandle);
for await (const [name] of this.#directoryHandle) {
- console.log("DELETING", name);
await this.#directoryHandle.removeEntry(name, { recursive: true });
}
}
diff --git a/apps/web/src/common/sqlite/IDBBatchAtomicVFS.js b/apps/web/src/common/sqlite/IDBBatchAtomicVFS.js
index 67a30f422..4832f7320 100644
--- a/apps/web/src/common/sqlite/IDBBatchAtomicVFS.js
+++ b/apps/web/src/common/sqlite/IDBBatchAtomicVFS.js
@@ -75,7 +75,6 @@ export class IDBBatchAtomicVFS extends VFS.Base {
}
async delete() {
- await this.close();
await deleteDatabase(this.name);
}
diff --git a/apps/web/src/common/sqlite/index.desktop.ts b/apps/web/src/common/sqlite/index.desktop.ts
index 787b5fb1a..8e49968e9 100644
--- a/apps/web/src/common/sqlite/index.desktop.ts
+++ b/apps/web/src/common/sqlite/index.desktop.ts
@@ -36,6 +36,7 @@ class SqliteDriver extends KSqliteDriver {
filePath: `userData/${this.config.name}.sql`
});
await desktop?.integration.deleteFile.query(path);
+ await this.destroy();
}
}
diff --git a/apps/web/src/common/sqlite/sqlite.worker.ts b/apps/web/src/common/sqlite/sqlite.worker.ts
index 8c7fe1586..d14fbd8aa 100644
--- a/apps/web/src/common/sqlite/sqlite.worker.ts
+++ b/apps/web/src/common/sqlite/sqlite.worker.ts
@@ -133,6 +133,7 @@ async function close() {
for (const [_, prepared] of preparedStatements) {
await sqlite.finalize(prepared.stmt);
}
+ preparedStatements.clear();
await sqlite.close(db);
await vfs?.close();
}
@@ -148,6 +149,7 @@ async function exportDatabase(dbName: string, async: boolean) {
}
async function deleteDatabase() {
+ await close();
await vfs?.delete();
}
diff --git a/apps/web/src/common/sqlite/wa-sqlite-kysely-driver.ts b/apps/web/src/common/sqlite/wa-sqlite-kysely-driver.ts
index cd4ae0461..972a1a21d 100644
--- a/apps/web/src/common/sqlite/wa-sqlite-kysely-driver.ts
+++ b/apps/web/src/common/sqlite/wa-sqlite-kysely-driver.ts
@@ -79,7 +79,6 @@ export class WaSqliteWorkerDriver implements Driver {
}
async delete() {
- console.log("DELETING");
return this.worker.delete();
}