mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	added "reloadNeeded" to consistency checks so that entity changes fix won't force reload
This commit is contained in:
		
							parent
							
								
									e4a483aefe
								
							
						
					
					
						commit
						a1c1c7c830
					
				| @ -19,6 +19,7 @@ class ConsistencyChecks { | |||||||
|         this.autoFix = autoFix; |         this.autoFix = autoFix; | ||||||
|         this.unrecoveredConsistencyErrors = false; |         this.unrecoveredConsistencyErrors = false; | ||||||
|         this.fixedIssues = false; |         this.fixedIssues = false; | ||||||
|  |         this.reloadNeeded = false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     findAndFixIssues(query, fixerCb) { |     findAndFixIssues(query, fixerCb) { | ||||||
| @ -104,6 +105,8 @@ class ConsistencyChecks { | |||||||
|                     const branch = becca.getBranch(branchId); |                     const branch = becca.getBranch(branchId); | ||||||
|                     branch.markAsDeleted(); |                     branch.markAsDeleted(); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Branch ${branchId} has been deleted since it references missing note ${noteId}`); |                     logFix(`Branch ${branchId} has been deleted since it references missing note ${noteId}`); | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Branch ${branchId} references missing note ${noteId}`); |                     logError(`Branch ${branchId} references missing note ${noteId}`); | ||||||
| @ -123,6 +126,8 @@ class ConsistencyChecks { | |||||||
|                     branch.parentNoteId = 'root'; |                     branch.parentNoteId = 'root'; | ||||||
|                     branch.save(); |                     branch.save(); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Branch ${branchId} was set to root parent since it was referencing missing parent note ${parentNoteId}`); |                     logFix(`Branch ${branchId} was set to root parent since it was referencing missing parent note ${parentNoteId}`); | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Branch ${branchId} references missing parent note ${parentNoteId}`); |                     logError(`Branch ${branchId} references missing parent note ${parentNoteId}`); | ||||||
| @ -140,6 +145,8 @@ class ConsistencyChecks { | |||||||
|                     const attribute = becca.getAttribute(attributeId); |                     const attribute = becca.getAttribute(attributeId); | ||||||
|                     attribute.markAsDeleted(); |                     attribute.markAsDeleted(); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Attribute ${attributeId} has been deleted since it references missing source note ${noteId}`); |                     logFix(`Attribute ${attributeId} has been deleted since it references missing source note ${noteId}`); | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Attribute ${attributeId} references missing source note ${noteId}`); |                     logError(`Attribute ${attributeId} references missing source note ${noteId}`); | ||||||
| @ -158,6 +165,8 @@ class ConsistencyChecks { | |||||||
|                     const attribute = becca.getAttribute(attributeId); |                     const attribute = becca.getAttribute(attributeId); | ||||||
|                     attribute.markAsDeleted(); |                     attribute.markAsDeleted(); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Relation ${attributeId} has been deleted since it references missing note ${noteId}`) |                     logFix(`Relation ${attributeId} has been deleted since it references missing note ${noteId}`) | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Relation ${attributeId} references missing note ${noteId}`) |                     logError(`Relation ${attributeId} references missing note ${noteId}`) | ||||||
| @ -183,6 +192,8 @@ class ConsistencyChecks { | |||||||
|                     const branch = becca.getBranch(branchId); |                     const branch = becca.getBranch(branchId); | ||||||
|                     branch.markAsDeleted(); |                     branch.markAsDeleted(); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Branch ${branchId} has been deleted since associated note ${noteId} is deleted.`); |                     logFix(`Branch ${branchId} has been deleted since associated note ${noteId} is deleted.`); | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Branch ${branchId} is not deleted even though associated note ${noteId} is deleted.`) |                     logError(`Branch ${branchId} is not deleted even though associated note ${noteId} is deleted.`) | ||||||
| @ -201,6 +212,8 @@ class ConsistencyChecks { | |||||||
|                 const branch = becca.getBranch(branchId); |                 const branch = becca.getBranch(branchId); | ||||||
|                 branch.markAsDeleted(); |                 branch.markAsDeleted(); | ||||||
| 
 | 
 | ||||||
|  |                 this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                 logFix(`Branch ${branchId} has been deleted since associated parent note ${parentNoteId} is deleted.`); |                 logFix(`Branch ${branchId} has been deleted since associated parent note ${parentNoteId} is deleted.`); | ||||||
|             } else { |             } else { | ||||||
|                 logError(`Branch ${branchId} is not deleted even though associated parent note ${parentNoteId} is deleted.`) |                 logError(`Branch ${branchId} is not deleted even though associated parent note ${parentNoteId} is deleted.`) | ||||||
| @ -221,6 +234,8 @@ class ConsistencyChecks { | |||||||
|                     prefix: 'recovered' |                     prefix: 'recovered' | ||||||
|                 }).save(); |                 }).save(); | ||||||
| 
 | 
 | ||||||
|  |                 this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                 logFix(`Created missing branch ${branch.branchId} for note ${noteId}`); |                 logFix(`Created missing branch ${branch.branchId} for note ${noteId}`); | ||||||
|             } else { |             } else { | ||||||
|                 logError(`No undeleted branch found for note ${noteId}`); |                 logError(`No undeleted branch found for note ${noteId}`); | ||||||
| @ -256,6 +271,8 @@ class ConsistencyChecks { | |||||||
| 
 | 
 | ||||||
|                         logFix(`Removing branch ${branch.branchId} since it's parent-child duplicate of branch ${origBranch.branchId}`); |                         logFix(`Removing branch ${branch.branchId} since it's parent-child duplicate of branch ${origBranch.branchId}`); | ||||||
|                     } |                     } | ||||||
|  | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Duplicate branches for note ${noteId} and parent ${parentNoteId}`); |                     logError(`Duplicate branches for note ${noteId} and parent ${parentNoteId}`); | ||||||
|                 } |                 } | ||||||
| @ -274,6 +291,8 @@ class ConsistencyChecks { | |||||||
|                     note.type = 'file'; // file is a safe option to recover notes if type is not known
 |                     note.type = 'file'; // file is a safe option to recover notes if type is not known
 | ||||||
|                     note.save(); |                     note.save(); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Note ${noteId} type has been change to file since it had invalid type=${type}`) |                     logFix(`Note ${noteId} type has been change to file since it had invalid type=${type}`) | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Note ${noteId} has invalid type=${type}`); |                     logError(`Note ${noteId} has invalid type=${type}`); | ||||||
| @ -311,6 +330,8 @@ class ConsistencyChecks { | |||||||
|                         isSynced: true |                         isSynced: true | ||||||
|                     }); |                     }); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Note ${noteId} content was set to empty string since there was no corresponding row`); |                     logFix(`Note ${noteId} content was set to empty string since there was no corresponding row`); | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Note ${noteId} content row does not exist`); |                     logError(`Note ${noteId} content row does not exist`); | ||||||
| @ -330,6 +351,8 @@ class ConsistencyChecks { | |||||||
|                     const blankContent = getBlankContent(false, type, mime); |                     const blankContent = getBlankContent(false, type, mime); | ||||||
|                     note.setContent(blankContent); |                     note.setContent(blankContent); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Note ${noteId} content was set to "${blankContent}" since it was null even though it is not deleted`); |                     logFix(`Note ${noteId} content was set to "${blankContent}" since it was null even though it is not deleted`); | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Note ${noteId} content is null even though it is not deleted`); |                     logError(`Note ${noteId} content is null even though it is not deleted`); | ||||||
| @ -346,6 +369,8 @@ class ConsistencyChecks { | |||||||
|                 if (this.autoFix) { |                 if (this.autoFix) { | ||||||
|                     noteRevisionService.eraseNoteRevisions([noteRevisionId]); |                     noteRevisionService.eraseNoteRevisions([noteRevisionId]); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Note revision content ${noteRevisionId} was created and set to erased since it did not exist.`); |                     logFix(`Note revision content ${noteRevisionId} was created and set to erased since it did not exist.`); | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Note revision content ${noteRevisionId} does not exist`); |                     logError(`Note revision content ${noteRevisionId} does not exist`); | ||||||
| @ -375,6 +400,8 @@ class ConsistencyChecks { | |||||||
| 
 | 
 | ||||||
|                         logFix(`Child branch ${branch.branchId} has been moved to root since it was a child of a search note ${parentNoteId}`) |                         logFix(`Child branch ${branch.branchId} has been moved to root since it was a child of a search note ${parentNoteId}`) | ||||||
|                     } |                     } | ||||||
|  | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Search note ${parentNoteId} has children`); |                     logError(`Search note ${parentNoteId} has children`); | ||||||
|                 } |                 } | ||||||
| @ -391,6 +418,8 @@ class ConsistencyChecks { | |||||||
|                     const relation = becca.getAttribute(attributeId); |                     const relation = becca.getAttribute(attributeId); | ||||||
|                     relation.markAsDeleted(); |                     relation.markAsDeleted(); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Removed relation ${relation.attributeId} of name "${relation.name} with empty target.`); |                     logFix(`Removed relation ${relation.attributeId} of name "${relation.name} with empty target.`); | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Relation ${attributeId} has empty target.`); |                     logError(`Relation ${attributeId} has empty target.`); | ||||||
| @ -410,6 +439,8 @@ class ConsistencyChecks { | |||||||
|                     attribute.type = 'label'; |                     attribute.type = 'label'; | ||||||
|                     attribute.save(); |                     attribute.save(); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Attribute ${attributeId} type was changed to label since it had invalid type '${type}'`); |                     logFix(`Attribute ${attributeId} type was changed to label since it had invalid type '${type}'`); | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Attribute ${attributeId} has invalid type '${type}'`); |                     logError(`Attribute ${attributeId} has invalid type '${type}'`); | ||||||
| @ -428,6 +459,8 @@ class ConsistencyChecks { | |||||||
|                     const attribute = becca.getAttribute(attributeId); |                     const attribute = becca.getAttribute(attributeId); | ||||||
|                     attribute.markAsDeleted(); |                     attribute.markAsDeleted(); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Removed attribute ${attributeId} because owning note ${noteId} is also deleted.`); |                     logFix(`Removed attribute ${attributeId} because owning note ${noteId} is also deleted.`); | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Attribute ${attributeId} is not deleted even though owning note ${noteId} is deleted.`); |                     logError(`Attribute ${attributeId} is not deleted even though owning note ${noteId} is deleted.`); | ||||||
| @ -447,6 +480,8 @@ class ConsistencyChecks { | |||||||
|                     const attribute = becca.getAttribute(attributeId); |                     const attribute = becca.getAttribute(attributeId); | ||||||
|                     attribute.markAsDeleted(); |                     attribute.markAsDeleted(); | ||||||
| 
 | 
 | ||||||
|  |                     this.reloadNeeded = true; | ||||||
|  | 
 | ||||||
|                     logFix(`Removed attribute ${attributeId} because target note ${targetNoteId} is also deleted.`); |                     logFix(`Removed attribute ${attributeId} because target note ${targetNoteId} is also deleted.`); | ||||||
|                 } else { |                 } else { | ||||||
|                     logError(`Attribute ${attributeId} is not deleted even though target note ${targetNoteId} is deleted.`); |                     logError(`Attribute ${attributeId} is not deleted even though target note ${targetNoteId} is deleted.`); | ||||||
| @ -530,6 +565,7 @@ class ConsistencyChecks { | |||||||
|                     sql.execute('UPDATE attributes SET name = ? WHERE name = ?', [fixedName, origName]); |                     sql.execute('UPDATE attributes SET name = ? WHERE name = ?', [fixedName, origName]); | ||||||
| 
 | 
 | ||||||
|                     this.fixedIssues = true; |                     this.fixedIssues = true; | ||||||
|  |                     this.reloadNeeded = true; | ||||||
| 
 | 
 | ||||||
|                     logFix(`Renamed incorrectly named attributes "${origName}" to ${fixedName}`); |                     logFix(`Renamed incorrectly named attributes "${origName}" to ${fixedName}`); | ||||||
|                 } |                 } | ||||||
| @ -565,6 +601,7 @@ class ConsistencyChecks { | |||||||
|     runAllChecksAndFixers() { |     runAllChecksAndFixers() { | ||||||
|         this.unrecoveredConsistencyErrors = false; |         this.unrecoveredConsistencyErrors = false; | ||||||
|         this.fixedIssues = false; |         this.fixedIssues = false; | ||||||
|  |         this.reloadNeeded = false; | ||||||
| 
 | 
 | ||||||
|         this.findBrokenReferenceIssues(); |         this.findBrokenReferenceIssues(); | ||||||
| 
 | 
 | ||||||
| @ -587,7 +624,7 @@ class ConsistencyChecks { | |||||||
|             this.checkTreeCycles(); |             this.checkTreeCycles(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (this.fixedIssues) { |         if (this.reloadNeeded) { | ||||||
|             require("../becca/becca_loader").reload(); |             require("../becca/becca_loader").reload(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam