sizing of the link map

This commit is contained in:
zadam
2021-09-22 23:02:38 +02:00
parent e3fc0968ba
commit fabf24a065
3 changed files with 33 additions and 95 deletions

View File

@@ -2,83 +2,6 @@
const becca = require("../../becca/becca");
function getRelations(noteId) {
const note = becca.getNote(noteId);
if (!note) {
throw new Error(noteId);
}
const allRelations = note.getOwnedRelations().concat(note.getTargetRelations());
return allRelations.filter(rel => {
if (rel.name === 'relationMapLink' || rel.name === 'template') {
return false;
}
else if (rel.name === 'imageLink') {
const parentNote = becca.getNote(rel.noteId);
return !parentNote.getChildNotes().find(childNote => childNote.noteId === rel.value);
}
else {
return true;
}
});
}
function collectRelations(noteId, relations, depth) {
if (depth === 0) {
return;
}
for (const relation of getRelations(noteId)) {
if (!relations.has(relation)) {
if (!relation.value) {
continue;
}
relations.add(relation);
if (relation.noteId !== noteId) {
collectRelations(relation.noteId, relations, depth - 1);
} else if (relation.value !== noteId) {
collectRelations(relation.value, relations, depth - 1);
}
}
}
}
function getLinkMap(req) {
const {noteId} = req.params;
const {maxDepth} = req.body;
let relations = new Set();
collectRelations(noteId, relations, maxDepth);
relations = Array.from(relations);
const noteIds = new Set(relations.map(rel => rel.noteId)
.concat(relations.map(rel => rel.targetNoteId))
.concat([noteId]));
const noteIdToLinkCountMap = {};
for (const noteId of noteIds) {
noteIdToLinkCountMap[noteId] = getRelations(noteId).length;
}
return {
noteIdToLinkCountMap,
links: Array.from(relations).map(rel => ({
id: rel.noteId + "-" + rel.name + "-" + rel.value,
sourceNoteId: rel.noteId,
targetNoteId: rel.value,
name: rel.name
}))
};
}
function buildDescendantCountMap() {
const noteIdToCountMap = {};
@@ -101,7 +24,7 @@ function buildDescendantCountMap() {
return noteIdToCountMap;
}
function getGlobalLinkMap(req) {
function getLinkMap(req) {
const mapRootNote = becca.getNote(req.params.noteId);
const noteIds = new Set();
@@ -145,7 +68,7 @@ function getGlobalLinkMap(req) {
};
}
function getGlobalTreeMap(req) {
function getTreeMap(req) {
const mapRootNote = becca.getNote(req.params.noteId);
const noteIds = new Set();
@@ -195,6 +118,5 @@ function getGlobalTreeMap(req) {
module.exports = {
getLinkMap,
getGlobalLinkMap,
getGlobalTreeMap
getTreeMap
};

View File

@@ -32,7 +32,7 @@ const senderRoute = require('./api/sender');
const filesRoute = require('./api/files');
const searchRoute = require('./api/search');
const specialNotesRoute = require('./api/special_notes.js');
const linkMapRoute = require('./api/link_map');
const noteMapRoute = require('./api/note_map.js');
const clipperRoute = require('./api/clipper');
const similarNotesRoute = require('./api/similar_notes');
const keysRoute = require('./api/keys');
@@ -220,9 +220,8 @@ function register(app) {
apiRoute(GET, '/api/attributes/names', attributesRoute.getAttributeNames);
apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute);
apiRoute(POST, '/api/notes/:noteId/link-map', linkMapRoute.getLinkMap);
apiRoute(POST, '/api/note-map/:noteId/tree', linkMapRoute.getGlobalTreeMap);
apiRoute(POST, '/api/note-map/:noteId/link', linkMapRoute.getGlobalLinkMap);
apiRoute(POST, '/api/note-map/:noteId/tree', noteMapRoute.getTreeMap);
apiRoute(POST, '/api/note-map/:noteId/link', noteMapRoute.getLinkMap);
apiRoute(GET, '/api/special-notes/inbox/:date', specialNotesRoute.getInboxNote);
apiRoute(GET, '/api/special-notes/date/:date', specialNotesRoute.getDateNote);