fix backlinks in day note subtree, fixes #3158

This commit is contained in:
zadam 2022-10-22 15:01:10 +02:00
parent 63eb22c7ac
commit 14fb9c76b0
4 changed files with 26 additions and 22 deletions

View File

@ -86,7 +86,7 @@ export default class BacklinksWidget extends NoteContextAwareWidget {
this.clearItems();
// can't use froca since that would count only relations from loaded notes
const resp = await server.get(`notes/${this.noteId}/backlink-count`);
const resp = await server.get(`note-map/${this.noteId}/backlink-count`);
if (!resp || !resp.count) {
this.toggle(false);

View File

@ -287,6 +287,27 @@ function findExcerpts(sourceNote, referencedNoteId) {
return excerpts;
}
function getFilteredBacklinks(note) {
return note.getTargetRelations()
// search notes have "ancestor" relations which are not interesting
.filter(note => note.getNote().type !== 'search');
}
function getBacklinkCount(req) {
const {noteId} = req.params;
const note = becca.getNote(noteId);
if (!note) {
return [404, "Not found"];
}
else {
return {
count: getFilteredBacklinks(note).length
};
}
}
function getBacklinks(req) {
const {noteId} = req.params;
const note = becca.getNote(noteId);
@ -295,11 +316,9 @@ function getBacklinks(req) {
return [404, `Note ${noteId} was not found`];
}
let backlinks = note.getTargetRelations();
let backlinksWithExcerptCount = 0;
return backlinks.filter(note => !note.getNote().hasLabel('excludeFromNoteMap')).map(backlink => {
return getFilteredBacklinks(note).map(backlink => {
const sourceNote = backlink.note;
if (sourceNote.type !== 'text' || backlinksWithExcerptCount > 50) {
@ -323,5 +342,6 @@ function getBacklinks(req) {
module.exports = {
getLinkMap,
getTreeMap,
getBacklinkCount,
getBacklinks
};

View File

@ -305,21 +305,6 @@ function uploadModifiedFile(req) {
note.setContent(fileContent);
}
function getBacklinkCount(req) {
const {noteId} = req.params;
const note = becca.getNote(noteId);
if (!note) {
return [404, "Not found"];
}
else {
return {
count: note.getTargetRelations().filter(note => !note.getNote().hasLabel('excludeFromNoteMap')).length
};
}
}
module.exports = {
getNote,
updateNoteContent,
@ -334,6 +319,5 @@ module.exports = {
duplicateSubtree,
eraseDeletedNotesNow,
getDeleteNotesPreview,
uploadModifiedFile,
getBacklinkCount
uploadModifiedFile
};

View File

@ -264,7 +264,6 @@ function register(app) {
apiRoute(DELETE, '/api/notes/:noteId/revisions/:noteRevisionId', noteRevisionsApiRoute.eraseNoteRevision);
route(GET, '/api/notes/:noteId/revisions/:noteRevisionId/download', [auth.checkApiAuthOrElectron], noteRevisionsApiRoute.downloadNoteRevision);
apiRoute(PUT, '/api/notes/:noteId/restore-revision/:noteRevisionId', noteRevisionsApiRoute.restoreNoteRevision);
apiRoute(GET, '/api/notes/:noteId/backlink-count', notesApiRoute.getBacklinkCount);
apiRoute(POST, '/api/notes/relation-map', notesApiRoute.getRelationMap);
apiRoute(POST, '/api/notes/erase-deleted-notes-now', notesApiRoute.eraseDeletedNotesNow);
apiRoute(PUT, '/api/notes/:noteId/title', notesApiRoute.changeTitle);
@ -306,6 +305,7 @@ function register(app) {
apiRoute(POST, '/api/note-map/:noteId/tree', noteMapRoute.getTreeMap);
apiRoute(POST, '/api/note-map/:noteId/link', noteMapRoute.getLinkMap);
apiRoute(GET, '/api/note-map/:noteId/backlink-count', noteMapRoute.getBacklinkCount);
apiRoute(GET, '/api/note-map/:noteId/backlinks', noteMapRoute.getBacklinks);
apiRoute(GET, '/api/special-notes/inbox/:date', specialNotesRoute.getInboxNote);