mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51:31 +08:00 
			
		
		
		
	delete attributes when deleting note
This commit is contained in:
		
							parent
							
								
									3204291463
								
							
						
					
					
						commit
						4513651e12
					
				| @ -7,6 +7,6 @@ instanceName= | |||||||
| port=8080 | port=8080 | ||||||
| # true for TLS/SSL/HTTPS (secure), false for HTTP (unsecure). | # true for TLS/SSL/HTTPS (secure), false for HTTP (unsecure). | ||||||
| https=false | https=false | ||||||
| # path to certificate (run "bash generate-cert.sh" to generate self-signed certificate). Relevant only if https=true | # path to certificate (run "bash bin/generate-cert.sh" to generate self-signed certificate). Relevant only if https=true | ||||||
| certPath= | certPath= | ||||||
| keyPath= | keyPath= | ||||||
|  | |||||||
| @ -34,7 +34,12 @@ function getNotePath(node) { | |||||||
| async function getNoteTitle(noteId, parentNoteId = null) { | async function getNoteTitle(noteId, parentNoteId = null) { | ||||||
|     utils.assertArguments(noteId); |     utils.assertArguments(noteId); | ||||||
| 
 | 
 | ||||||
|     let {title} = await treeCache.getNote(noteId); |     const note = await treeCache.getNote(noteId); | ||||||
|  |     if (!note) { | ||||||
|  |         return "[not found]"; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     let {title} = note; | ||||||
| 
 | 
 | ||||||
|     if (parentNoteId !== null) { |     if (parentNoteId !== null) { | ||||||
|         const branch = await treeCache.getBranchByChildParent(noteId, parentNoteId); |         const branch = await treeCache.getBranchByChildParent(noteId, parentNoteId); | ||||||
|  | |||||||
| @ -79,6 +79,9 @@ async function importTar(file, parentNoteId) { | |||||||
|     const noteIdMap = {}; |     const noteIdMap = {}; | ||||||
| 
 | 
 | ||||||
|     await importNotes(files, parentNoteId, noteIdMap); |     await importNotes(files, parentNoteId, noteIdMap); | ||||||
|  | 
 | ||||||
|  |     // import might contain relations targeting notes which are not in the import
 | ||||||
|  |     await attributeService.removeInvalidRelations(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function getFileName(name) { | function getFileName(name) { | ||||||
|  | |||||||
| @ -77,11 +77,31 @@ async function getAttributeNames(type, nameLike) { | |||||||
|     return names; |     return names; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | async function removeInvalidRelations() { | ||||||
|  |     const relations = await repository.getEntities(` | ||||||
|  |       SELECT attributes.*  | ||||||
|  |       FROM attributes  | ||||||
|  |           LEFT JOIN notes AS sourceNote ON attributes.noteId = sourceNote.noteId | ||||||
|  |           LEFT JOIN notes AS targetNote ON attributes.value = targetNote.noteId | ||||||
|  |       WHERE  | ||||||
|  |           attributes.isDeleted = 0 | ||||||
|  |           AND attributes.type = 'relation' | ||||||
|  |           AND (sourceNote.noteId IS NULL OR sourceNote.isDeleted | ||||||
|  |                OR targetNote.noteId IS NULL OR targetNote.isDeleted)`);
 | ||||||
|  | 
 | ||||||
|  |     for (const relation of relations) { | ||||||
|  |         relation.isDeleted = true; | ||||||
|  | 
 | ||||||
|  |         await relation.save(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| module.exports = { | module.exports = { | ||||||
|     getNotesWithLabel, |     getNotesWithLabel, | ||||||
|     getNoteWithLabel, |     getNoteWithLabel, | ||||||
|     createLabel, |     createLabel, | ||||||
|     createAttribute, |     createAttribute, | ||||||
|     getAttributeNames, |     getAttributeNames, | ||||||
|  |     removeInvalidRelations, | ||||||
|     BUILTIN_ATTRIBUTES |     BUILTIN_ATTRIBUTES | ||||||
| }; | }; | ||||||
| @ -250,6 +250,11 @@ async function deleteNote(branch) { | |||||||
|         for (const childBranch of await note.getChildBranches()) { |         for (const childBranch of await note.getChildBranches()) { | ||||||
|             await deleteNote(childBranch); |             await deleteNote(childBranch); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         for (const attribute of await note.getOwnedAttributes()) { | ||||||
|  |             attribute.isDeleted = true; | ||||||
|  |             await attribute.save(); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner