From 521a9b0b2c78a770c858ba58b0ae57a469749dd0 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 7 Sep 2019 22:36:08 +0200 Subject: [PATCH] link map will try to display max possible number of links --- src/routes/api/link_map.js | 20 +++++++++++--------- src/services/notes.js | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/routes/api/link_map.js b/src/routes/api/link_map.js index 1faa11d20..e59233ce2 100644 --- a/src/routes/api/link_map.js +++ b/src/routes/api/link_map.js @@ -23,27 +23,29 @@ async function getLinkMap(req) { let depth = 0; - while (true) { + while (noteIds.size < maxNotes) { relations = await getRelations(noteIds); if (depth === maxDepth) { break; } - const newNoteIds = new Set(relations.map(rel => rel.noteId) - .concat(relations.map(rel => rel.targetNoteId))); + let newNoteIds = relations.map(rel => rel.noteId) + .concat(relations.map(rel => rel.targetNoteId)) + .filter(noteId => !noteIds.has(noteId)); - if (newNoteIds.size === noteIds.size) { + if (newNoteIds.length === 0) { // no new note discovered, no need to search any further break; } - if (newNoteIds.size > maxNotes) { - // too many notes to display - break; - } + for (const newNoteId of newNoteIds) { + noteIds.add(newNoteId); - noteIds = newNoteIds; + if (noteIds.size >= maxNotes) { + break; + } + } depth++; } diff --git a/src/services/notes.js b/src/services/notes.js index f6c81040a..87c988ad2 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -102,7 +102,7 @@ async function createNewNote(parentNoteId, noteData) { mime: noteData.mime || 'text/html' }).save(); - if (note.isStringNote()) { + if (note.isStringNote() || this.type === 'render') { // render to just make sure it's not null noteData.content = noteData.content || ""; }