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
fix: repair all notebook references on sync/backup
thecodrr64535cc61cc6
diff --git a/packages/core/api/sync/merger.js b/packages/core/api/sync/merger.jsindex e83d28f0a..dd4eb87ec 100644--- a/packages/core/api/sync/merger.js+++ b/packages/core/api/sync/merger.js@@ -183,6 +183,7 @@ class Merger {);await this._db.notes.repairReferences();+ await this._db.notebooks.repairReferences();return true;}}diff --git a/packages/core/collections/notebooks.js b/packages/core/collections/notebooks.jsindex cd5399a14..947dd2b05 100644--- a/packages/core/collections/notebooks.js+++ b/packages/core/collections/notebooks.js@@ -133,4 +133,14 @@ export default class Notebooks extends Collection {await this._db.trash.add(notebookData);}}++ async repairReferences() {+ for (let notebook of this.all) {+ const _notebook = this.notebook(notebook.id);+ for (let topic of notebook.topics) {+ const _topic = _notebook.topics.topic(topic.id);+ await _topic.add(...topic.notes);+ }+ }+ }}diff --git a/packages/core/database/backup.js b/packages/core/database/backup.jsindex 255980b80..54d67c9d2 100644--- a/packages/core/database/backup.js+++ b/packages/core/database/backup.js@@ -142,6 +142,7 @@ export default class Backup {if (await this._migrator.migrate(collections, (id) => data[id], version)) {await this._db.notes.repairReferences();+ await this._db.notebooks.repairReferences();}}diff --git a/packages/core/models/topic.js b/packages/core/models/topic.jsindex 8e6932431..e5edf2d1b 100644--- a/packages/core/models/topic.js+++ b/packages/core/models/topic.js@@ -26,7 +26,7 @@ export default class Topic {const topic = qclone(this._topic);for (let noteId of noteIds) {let note = this._db.notes.note(noteId);- if (this.has(noteId) || !note || note.data.deleted) continue;+ if (!note || note.data.deleted) continue;let array = note.notebooks || [];const notebookIndex = array.findIndex((nb) => nb.id === this._notebookId);@@ -50,7 +50,7 @@ export default class Topic {notebooks: array,});- topic.notes.push(noteId);+ if (!this.has(noteId)) topic.notes.push(noteId);}return await this._save(topic);}