mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-30 19:19:03 +01:00 
			
		
		
		
	fix erasing revisions
This commit is contained in:
		
							parent
							
								
									84feaabc52
								
							
						
					
					
						commit
						d0f6ff5f98
					
				| @ -8,6 +8,7 @@ const cls = require('../../services/cls'); | ||||
| const path = require('path'); | ||||
| const becca = require("../../becca/becca"); | ||||
| const blobService = require("../../services/blob"); | ||||
| const eraseService = require("../../services/erase.js"); | ||||
| 
 | ||||
| function getRevisionBlob(req) { | ||||
|     const preview = req.query.preview === 'true'; | ||||
| @ -88,11 +89,11 @@ function eraseAllRevisions(req) { | ||||
|     const revisionIdsToErase = sql.getColumn('SELECT revisionId FROM revisions WHERE noteId = ?', | ||||
|         [req.params.noteId]); | ||||
| 
 | ||||
|     revisionService.eraseRevisions(revisionIdsToErase); | ||||
|     eraseService.eraseRevisions(revisionIdsToErase); | ||||
| } | ||||
| 
 | ||||
| function eraseRevision(req) { | ||||
|     revisionService.eraseRevisions([req.params.revisionId]); | ||||
|     eraseService.eraseRevisions([req.params.revisionId]); | ||||
| } | ||||
| 
 | ||||
| function restoreRevision(req) { | ||||
|  | ||||
| @ -4,6 +4,7 @@ const becca = require("../becca/becca"); | ||||
| const cloningService = require("./cloning"); | ||||
| const branchService = require("./branches"); | ||||
| const utils = require("./utils"); | ||||
| const eraseService = require("./erase.js"); | ||||
| 
 | ||||
| const ACTION_HANDLERS = { | ||||
|     addLabel: (action, note) => { | ||||
| @ -18,7 +19,7 @@ const ACTION_HANDLERS = { | ||||
|         note.deleteNote(deleteId); | ||||
|     }, | ||||
|     deleteRevisions: (action, note) => { | ||||
|         revisionService.eraseRevisions(note.getRevisions().map(rev => rev.revisionId)); | ||||
|         eraseService.eraseRevisions(note.getRevisions().map(rev => rev.revisionId)); | ||||
|     }, | ||||
|     deleteLabel: (action, note) => { | ||||
|         for (const label of note.getOwnedLabels(action.labelName)) { | ||||
|  | ||||
| @ -467,7 +467,7 @@ class ConsistencyChecks { | ||||
|                     WHERE blobs.blobId IS NULL`,
 | ||||
|             ({revisionId, blobId}) => { | ||||
|                 if (this.autoFix) { | ||||
|                     revisionService.eraseRevisions([revisionId]); | ||||
|                     eraseService.eraseRevisions([revisionId]); | ||||
| 
 | ||||
|                     this.reloadNeeded = true; | ||||
| 
 | ||||
|  | ||||
| @ -29,7 +29,7 @@ function eraseNotes(noteIdsToErase) { | ||||
|     const revisionIdsToErase = sql.getManyRows(`SELECT revisionId FROM revisions WHERE noteId IN (???)`, noteIdsToErase) | ||||
|         .map(row => row.revisionId); | ||||
| 
 | ||||
|     revisionService.eraseRevisions(revisionIdsToErase); | ||||
|     eraseRevisions(revisionIdsToErase); | ||||
| 
 | ||||
|     log.info(`Erased notes: ${JSON.stringify(noteIdsToErase)}`); | ||||
| } | ||||
| @ -79,6 +79,18 @@ function eraseAttachments(attachmentIdsToErase) { | ||||
|     log.info(`Erased attachments: ${JSON.stringify(attachmentIdsToErase)}`); | ||||
| } | ||||
| 
 | ||||
| function eraseRevisions(revisionIdsToErase) { | ||||
|     if (revisionIdsToErase.length === 0) { | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     sql.executeMany(`DELETE FROM revisions WHERE revisionId IN (???)`, revisionIdsToErase); | ||||
| 
 | ||||
|     setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'revisions' AND entityId IN (???)`, revisionIdsToErase)); | ||||
| 
 | ||||
|     log.info(`Removed revisions: ${JSON.stringify(revisionIdsToErase)}`); | ||||
| } | ||||
| 
 | ||||
| function eraseUnusedBlobs() { | ||||
|     const unusedBlobIds = sql.getColumn(` | ||||
|         SELECT blobs.blobId | ||||
| @ -184,5 +196,6 @@ module.exports = { | ||||
|     eraseUnusedAttachmentsNow, | ||||
|     eraseNotesWithDeleteId, | ||||
|     eraseUnusedBlobs, | ||||
|     eraseAttachments | ||||
|     eraseAttachments, | ||||
|     eraseRevisions | ||||
| }; | ||||
|  | ||||
| @ -46,18 +46,6 @@ function protectRevisions(note) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| function eraseRevisions(revisionIdsToErase) { | ||||
|     if (revisionIdsToErase.length === 0) { | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     log.info(`Removing revisions: ${JSON.stringify(revisionIdsToErase)}`); | ||||
| 
 | ||||
|     sql.executeMany(`DELETE FROM revisions WHERE revisionId IN (???)`, revisionIdsToErase); | ||||
|     sql.executeMany(`UPDATE entity_changes SET isErased = 1, utcDateChanged = '${dateUtils.utcNowDateTime()}' WHERE entityName = 'revisions' AND entityId IN (???)`, revisionIdsToErase); | ||||
| } | ||||
| 
 | ||||
| module.exports = { | ||||
|     protectRevisions, | ||||
|     eraseRevisions | ||||
|     protectRevisions | ||||
| }; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam