Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
check reference issues only for non deleted entities
zadamd8b78d802512
diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex d8eadd78c3..63fa789197 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -92,38 +92,39 @@ async function findBrokenReferenceIssues() {await findIssues(`SELECT branchId, branches.noteIdFROM branches LEFT JOIN notes USING(noteId)- WHERE notes.noteId IS NULL`,+ WHERE branches.isDeleted = 0 AND notes.noteId IS NULL`,({branchId, noteId}) => `Branch ${branchId} references missing note ${noteId}`);await findIssues(`SELECT branchId, branches.noteId AS parentNoteIdFROM branches LEFT JOIN notes ON notes.noteId = branches.parentNoteId- WHERE branches.branchId != 'root' AND notes.noteId IS NULL`,+ WHERE branches.isDeleted = 0 AND branches.branchId != 'root' AND notes.noteId IS NULL`,({branchId, noteId}) => `Branch ${branchId} references missing parent note ${noteId}`);await findIssues(`SELECT attributeId, attributes.noteIdFROM attributes LEFT JOIN notes USING(noteId)- WHERE notes.noteId IS NULL`,+ WHERE attributes.isDeleted = 0 AND notes.noteId IS NULL`,({attributeId, noteId}) => `Attribute ${attributeId} references missing source note ${noteId}`);// empty targetNoteId for relations is a special fixable case so not covered hereawait findIssues(`SELECT attributeId, attributes.value AS noteIdFROM attributes LEFT JOIN notes ON notes.noteId = attributes.value- WHERE attributes.type = 'relation' AND attributes.value != '' AND notes.noteId IS NULL`,+ WHERE attributes.isDeleted = 0 AND attributes.type = 'relation'+ AND attributes.value != '' AND notes.noteId IS NULL`,({attributeId, noteId}) => `Relation ${attributeId} references missing note ${noteId}`);await findIssues(`SELECT linkId, links.noteIdFROM links LEFT JOIN notes USING(noteId)- WHERE notes.noteId IS NULL`,+ WHERE links.isDeleted = 0 AND notes.noteId IS NULL`,({linkId, noteId}) => `Link ${linkId} references missing source note ${noteId}`);await findIssues(`SELECT linkId, links.noteIdFROM links LEFT JOIN notes ON notes.noteId = links.targetNoteId- WHERE notes.noteId IS NULL`,+ WHERE links.isDeleted = 0 AND notes.noteId IS NULL`,({linkId, noteId}) => `Link ${linkId} references missing target note ${noteId}`);await findIssues(`