Skip to content

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

fix: only remove references when repairing note

thecodrrbde01e1e542b
diff --git a/packages/core/__tests__/notes.test.js b/packages/core/__tests__/notes.test.js
index b187ba4fc..ddabe5c4d 100644
--- a/packages/core/__tests__/notes.test.js
+++ b/packages/core/__tests__/notes.test.js
@@ -329,11 +329,13 @@ test("note content should not contain image base64 data after save", () =>
test("repairing notebook references should reinclude the missing noteIds", () =>
notebookTest().then(async ({ db, id }) => {
const notebook = db.notebooks.notebook(id);
- const note = {
+ let note = {
...TEST_NOTE,
notebooks: [{ id, topics: [notebook.topics.all[0].id] }],
};
- await db.notes.add(note);
+ const noteId = await db.notes.add(note);
await db.notes.repairReferences();
- expect(notebook.topics.all[0].notes.length).toBe(1);
+ note = db.notes.note(noteId);
+ expect(notebook.topics.all[0].notes.length).toBe(0);
+ expect(note.notebooks.length).toBe(0);
}));
diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.js
index 0af22e02b..3afeadeab 100644
--- a/packages/core/collections/notes.js
+++ b/packages/core/collections/notes.js
@@ -249,17 +249,19 @@ export default class Notes extends Collection {
for (let notebook of notebooks) {
const nb = this._db.notebooks.notebook(notebook.id);
- if (!nb) {
- deleteItem(notebooks, notebook);
- continue;
- }
for (let topic of notebook.topics) {
const _topic = nb.topics.topic(topic);
if (!_topic || !_topic.has(note.id)) {
deleteItem(notebook.topics, topic);
+ await this.add(note);
continue;
}
- await _topic.add(note.id);
+ }
+
+ if (!nb || !notebook.topics.length) {
+ deleteItem(notebooks, notebook);
+ await this.add(note);
+ continue;
}
}
}