mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
fix: repair all notebook references on sync/backup
This commit is contained in:
@@ -183,6 +183,7 @@ class Merger {
|
||||
);
|
||||
|
||||
await this._db.notes.repairReferences();
|
||||
await this._db.notebooks.repairReferences();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user