configuration of displayed link types + max number of links

This commit is contained in:
zadam
2019-06-10 14:33:59 +02:00
parent ccbb2e2e12
commit 8ab081a3fd
7 changed files with 82 additions and 19 deletions

View File

@@ -2,8 +2,8 @@
const sql = require('../../services/sql');
async function getLinks(noteIds) {
return await sql.getManyRows(`
async function getLinks(noteIds, linkTypes) {
return (await sql.getManyRows(`
SELECT noteId, targetNoteId, type
FROM links
WHERE (noteId IN (???) OR targetNoteId IN (???))
@@ -14,17 +14,18 @@ async function getLinks(noteIds) {
WHERE (noteId IN (???) OR value IN (???))
AND type = 'relation'
AND isDeleted = 0
`, Array.from(noteIds));
`, Array.from(noteIds))).filter(l => linkTypes.includes(l.type));
}
async function getLinkMap(req) {
const {noteId} = req.params;
const {linkTypes, maxNotes} = req.body;
let noteIds = new Set([noteId]);
let links = [];
while (true) {
const newLinks = await getLinks(noteIds);
const newLinks = await getLinks(noteIds, linkTypes);
const newNoteIds = new Set(newLinks.map(l => l.noteId).concat(newLinks.map(l => l.targetNoteId)));
if (newNoteIds.size === noteIds.size) {
@@ -32,7 +33,7 @@ async function getLinkMap(req) {
break;
}
if (newNoteIds.length > 50) {
if (newNoteIds.size > maxNotes) {
// to many notes to display
break;
}