mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 20:06:08 +01:00
Link entity migrated to Attribute, WIP
This commit is contained in:
@@ -2,38 +2,34 @@
|
||||
|
||||
const sql = require('../../services/sql');
|
||||
|
||||
async function getLinks(noteIds, linkTypes) {
|
||||
async function getRelations(noteIds, relationNames) {
|
||||
return (await sql.getManyRows(`
|
||||
SELECT noteId, targetNoteId, type
|
||||
FROM links
|
||||
WHERE (noteId IN (???) OR targetNoteId IN (???))
|
||||
AND isDeleted = 0
|
||||
UNION
|
||||
SELECT noteId, value, 'relation'
|
||||
SELECT noteId, name, value AS targetNoteId
|
||||
FROM attributes
|
||||
WHERE (noteId IN (???) OR value IN (???))
|
||||
AND type = 'relation'
|
||||
AND isDeleted = 0
|
||||
`, Array.from(noteIds))).filter(l => linkTypes.includes(l.type));
|
||||
`, Array.from(noteIds))).filter(l => relationNames.includes(l.name));
|
||||
}
|
||||
|
||||
async function getLinkMap(req) {
|
||||
const {noteId} = req.params;
|
||||
const {linkTypes, maxNotes, maxDepth} = req.body;
|
||||
const {relationNames, maxNotes, maxDepth} = req.body;
|
||||
|
||||
let noteIds = new Set([noteId]);
|
||||
let links = [];
|
||||
let relations;
|
||||
|
||||
let depth = 0;
|
||||
|
||||
while (true) {
|
||||
links = await getLinks(noteIds, linkTypes);
|
||||
relations = await getRelations(noteIds, relationNames);
|
||||
|
||||
if (depth === maxDepth) {
|
||||
break;
|
||||
}
|
||||
|
||||
const newNoteIds = new Set(links.map(l => l.noteId).concat(links.map(l => l.targetNoteId)));
|
||||
const newNoteIds = new Set(relations.map(rel => rel.noteId)
|
||||
.concat(relations.map(rel => rel.targetNoteId)));
|
||||
|
||||
if (newNoteIds.size === noteIds.size) {
|
||||
// no new note discovered, no need to search any further
|
||||
@@ -51,9 +47,9 @@ async function getLinkMap(req) {
|
||||
}
|
||||
|
||||
// keep only links coming from and targetting some note in the noteIds set
|
||||
links = links.filter(l => noteIds.has(l.noteId) && noteIds.has(l.targetNoteId));
|
||||
relations = relations.filter(rel => noteIds.has(rel.noteId) && noteIds.has(rel.targetNoteId));
|
||||
|
||||
return links;
|
||||
return relations;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user