A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: defer notes loading
thecodrr1eee45643e1c
diff --git a/packages/core/__tests__/trash.test.js b/packages/core/__tests__/trash.test.jsindex fb055b0a8..a5c1d1d2d 100644--- a/packages/core/__tests__/trash.test.js+++ b/packages/core/__tests__/trash.test.js@@ -83,7 +83,7 @@ test("restore a deleted note that's in a deleted notebook", () =>await db.trash.restore(deletedNote.id);let note = db.notes.note(id);expect(note).toBeDefined();- expect(db.notes.note(id).notebook).toStrictEqual({});+ expect(db.notes.note(id).notebook).toBeUndefined();}));test("delete a notebook", () =>diff --git a/packages/core/api/index.js b/packages/core/api/index.jsindex e91969007..310968d38 100644--- a/packages/core/api/index.js+++ b/packages/core/api/index.js@@ -58,7 +58,7 @@ class Database {// collections/** @type {Notes} */- this.notes = await Notes.new(this, "notes");+ this.notes = await Notes.new(this, "notes", true, true);/** @type {Notebooks} */this.notebooks = await Notebooks.new(this, "notebooks");/** @type {Tags} */diff --git a/packages/core/collections/collection.js b/packages/core/collections/collection.jsindex 1532ed96b..775581c8f 100644--- a/packages/core/collections/collection.js+++ b/packages/core/collections/collection.js@@ -3,11 +3,10 @@ import CachedCollection from "../database/cached-collection";import IndexedCollection from "../database/indexed-collection";class Collection {- static async new(db, name, cached = true) {+ static async new(db, name, cached = true, deferred = false) {const collection = new this(db, name, cached);- await collection._collection.init();- if (collection.init) await collection.init();+ if (!deferred && collection.init) await collection.init();if (collection._collection.clear)EV.subscribe("user:loggedOut",@@ -17,6 +16,10 @@ class Collection {return collection;}+ async init() {+ await this._collection.init();+ }+/**** @param {import("../api").default} dbdiff --git a/packages/core/collections/trash.js b/packages/core/collections/trash.jsindex fa5cc4a45..da909bf7a 100644--- a/packages/core/collections/trash.js+++ b/packages/core/collections/trash.js@@ -4,6 +4,7 @@ import { get7DayTimestamp } from "../utils/date";export default class Trash extends Collection {async init() {+ await super.init();await this.cleanup();}@@ -77,7 +78,7 @@ export default class Trash extends Collection {}// restore the note to the topic it was in before deletion- if (notebook.id && notebook.topic) {+ if (notebook && notebook.id && notebook.topic) {await this._db.notebooks.notebook(id).topics.topic(topic)diff --git a/packages/core/database/cached-collection.js b/packages/core/database/cached-collection.jsindex 0f026790b..bab88c2d8 100644--- a/packages/core/database/cached-collection.js+++ b/packages/core/database/cached-collection.js@@ -6,6 +6,7 @@ import IndexedCollection from "./indexed-collection";export default class CachedCollection extends IndexedCollection {constructor(context, type) {super(context, type);+ this.map = new Map();}async init() {