mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	link fixes
This commit is contained in:
		| @@ -55,13 +55,11 @@ class LinkMapWidget extends StandardWidget { | |||||||
|     async loadNotesAndRelations() { |     async loadNotesAndRelations() { | ||||||
|         this.cleanup(); |         this.cleanup(); | ||||||
|  |  | ||||||
|         const linkTypes = [ "hyper", "image", "relation", "relation-map" ]; |  | ||||||
|         const maxNotes = 50; |         const maxNotes = 50; | ||||||
|  |  | ||||||
|         const currentNoteId = this.ctx.note.noteId; |         const currentNoteId = this.ctx.note.noteId; | ||||||
|  |  | ||||||
|         const links = await server.post(`notes/${currentNoteId}/link-map`, { |         const links = await server.post(`notes/${currentNoteId}/link-map`, { | ||||||
|             linkTypes, |  | ||||||
|             maxNotes, |             maxNotes, | ||||||
|             maxDepth: 1 |             maxDepth: 1 | ||||||
|         }); |         }); | ||||||
|   | |||||||
| @@ -9,12 +9,12 @@ async function getRelations(noteIds, relationNames) { | |||||||
|         WHERE (noteId IN (???) OR value IN (???)) |         WHERE (noteId IN (???) OR value IN (???)) | ||||||
|           AND type = 'relation' |           AND type = 'relation' | ||||||
|           AND isDeleted = 0 |           AND isDeleted = 0 | ||||||
|     `, Array.from(noteIds))).filter(l => relationNames.includes(l.name)); |     `, Array.from(noteIds))); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function getLinkMap(req) { | async function getLinkMap(req) { | ||||||
|     const {noteId} = req.params; |     const {noteId} = req.params; | ||||||
|     const {relationNames, maxNotes, maxDepth} = req.body; |     const {maxNotes, maxDepth} = req.body; | ||||||
|  |  | ||||||
|     let noteIds = new Set([noteId]); |     let noteIds = new Set([noteId]); | ||||||
|     let relations; |     let relations; | ||||||
| @@ -22,7 +22,7 @@ async function getLinkMap(req) { | |||||||
|     let depth = 0; |     let depth = 0; | ||||||
|  |  | ||||||
|     while (true) { |     while (true) { | ||||||
|         relations = await getRelations(noteIds, relationNames); |         relations = await getRelations(noteIds); | ||||||
|  |  | ||||||
|         if (depth === maxDepth) { |         if (depth === maxDepth) { | ||||||
|             break; |             break; | ||||||
|   | |||||||
| @@ -115,18 +115,6 @@ async function findBrokenReferenceIssues() { | |||||||
|             AND attributes.value != '' AND notes.noteId IS NULL`, |             AND attributes.value != '' AND notes.noteId IS NULL`, | ||||||
|         ({attributeId, noteId}) => `Relation ${attributeId} references missing note ${noteId}`); |         ({attributeId, noteId}) => `Relation ${attributeId} references missing note ${noteId}`); | ||||||
|  |  | ||||||
|     await findIssues(` |  | ||||||
|           SELECT linkId, links.noteId |  | ||||||
|           FROM links LEFT JOIN notes USING(noteId) |  | ||||||
|           WHERE links.isDeleted = 0 AND notes.noteId IS NULL`, |  | ||||||
|         ({linkId, noteId}) => `Link ${linkId} references missing source note ${noteId}`); |  | ||||||
|  |  | ||||||
|     await findIssues(` |  | ||||||
|           SELECT linkId, links.noteId |  | ||||||
|           FROM links LEFT JOIN notes ON notes.noteId = links.targetNoteId |  | ||||||
|           WHERE links.isDeleted = 0 AND notes.noteId IS NULL`, |  | ||||||
|         ({linkId, noteId}) => `Link ${linkId} references missing target note ${noteId}`); |  | ||||||
|  |  | ||||||
|     await findIssues(` |     await findIssues(` | ||||||
|           SELECT noteRevisionId, note_revisions.noteId |           SELECT noteRevisionId, note_revisions.noteId | ||||||
|           FROM note_revisions LEFT JOIN notes USING(noteId) |           FROM note_revisions LEFT JOIN notes USING(noteId) | ||||||
| @@ -135,7 +123,7 @@ async function findBrokenReferenceIssues() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function findExistencyIssues() { | async function findExistencyIssues() { | ||||||
|     // principle for fixing inconsistencies is that if the note itself is deleted (isDeleted=true) then all related entities should be also deleted (branches, links, attributes) |     // principle for fixing inconsistencies is that if the note itself is deleted (isDeleted=true) then all related entities should be also deleted (branches, attributes) | ||||||
|     // but if note is not deleted, then at least one branch should exist. |     // but if note is not deleted, then at least one branch should exist. | ||||||
|  |  | ||||||
|     // the order here is important - first we might need to delete inconsistent branches and after that |     // the order here is important - first we might need to delete inconsistent branches and after that | ||||||
| @@ -315,48 +303,6 @@ async function findLogicIssues() { | |||||||
|  |  | ||||||
|             logFix(`Removed attribute ${attributeId} because target note ${targetNoteId} is also deleted.`); |             logFix(`Removed attribute ${attributeId} because target note ${targetNoteId} is also deleted.`); | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|     await findIssues(` |  | ||||||
|           SELECT linkId |  | ||||||
|           FROM links |  | ||||||
|           WHERE type NOT IN ('image', 'hyper', 'relation-map')`, |  | ||||||
|         ({linkId, type}) => `Link ${linkId} has invalid type '${type}'`); |  | ||||||
|  |  | ||||||
|     await findAndFixIssues(` |  | ||||||
|           SELECT |  | ||||||
|             linkId, |  | ||||||
|             links.noteId AS sourceNoteId |  | ||||||
|           FROM |  | ||||||
|             links |  | ||||||
|               JOIN notes AS sourceNote ON sourceNote.noteId = links.noteId |  | ||||||
|           WHERE |  | ||||||
|             links.isDeleted = 0 |  | ||||||
|             AND sourceNote.isDeleted = 1`, |  | ||||||
|         async ({linkId, sourceNoteId}) => { |  | ||||||
|             const link = await repository.getLink(linkId); |  | ||||||
|             link.isDeleted = true; |  | ||||||
|             await link.save(); |  | ||||||
|  |  | ||||||
|             logFix(`Removed link ${linkId} because source note ${sourceNoteId} is also deleted.`); |  | ||||||
|         }); |  | ||||||
|  |  | ||||||
|     await findAndFixIssues(` |  | ||||||
|           SELECT  |  | ||||||
|             linkId, |  | ||||||
|             links.targetNoteId |  | ||||||
|           FROM  |  | ||||||
|             links |  | ||||||
|             JOIN notes AS targetNote ON targetNote.noteId = links.targetNoteId |  | ||||||
|           WHERE |  | ||||||
|             links.isDeleted = 0 |  | ||||||
|             AND targetNote.isDeleted = 1`, |  | ||||||
|         async ({linkId, targetNoteId}) => { |  | ||||||
|             const link = await repository.getLink(linkId); |  | ||||||
|             link.isDeleted = true; |  | ||||||
|             await link.save(); |  | ||||||
|  |  | ||||||
|             logFix(`Removed link ${linkId} because target note ${targetNoteId} is also deleted.`); |  | ||||||
|         }); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| async function runSyncRowChecks(entityName, key) { | async function runSyncRowChecks(entityName, key) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user