mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	enex import cleanup
This commit is contained in:
		
							parent
							
								
									6662b9dbf9
								
							
						
					
					
						commit
						fd6b2f1e7f
					
				| @ -39,10 +39,6 @@ function importEnex(taskContext, file, parentNote) { | |||||||
|         isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(), |         isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(), | ||||||
|     })).note; |     })).note; | ||||||
| 
 | 
 | ||||||
|     // we're persisting notes as we parse the document, but these are run asynchronously and may not be finished
 |  | ||||||
|     // when we finish parsing. We use this to be sure that all saving has been finished before returning successfully.
 |  | ||||||
|     const saveNotePromises = []; |  | ||||||
| 
 |  | ||||||
|     function extractContent(content) { |     function extractContent(content) { | ||||||
|         const openingNoteIndex = content.indexOf('<en-note>'); |         const openingNoteIndex = content.indexOf('<en-note>'); | ||||||
| 
 | 
 | ||||||
| @ -314,13 +310,7 @@ function importEnex(taskContext, file, parentNote) { | |||||||
|         updateDates(noteEntity.noteId, utcDateCreated, utcDateModified); |         updateDates(noteEntity.noteId, utcDateCreated, utcDateModified); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     saxStream.on("closetag", tag => { |     saxStream.on("closetag", tag => path.pop()); | ||||||
|         path.pop(); |  | ||||||
| 
 |  | ||||||
|         if (tag === 'note') { |  | ||||||
|             saveNotePromises.push(saveNote()); |  | ||||||
|         } |  | ||||||
|     }); |  | ||||||
| 
 | 
 | ||||||
|     saxStream.on("opencdata", () => { |     saxStream.on("opencdata", () => { | ||||||
|         //console.log("opencdata");
 |         //console.log("opencdata");
 | ||||||
| @ -337,14 +327,14 @@ function importEnex(taskContext, file, parentNote) { | |||||||
|     return new Promise((resolve, reject) => |     return new Promise((resolve, reject) => | ||||||
|     { |     { | ||||||
|         // resolve only when we parse the whole document AND saving of all notes have been finished
 |         // resolve only when we parse the whole document AND saving of all notes have been finished
 | ||||||
|         saxStream.on("end", () => { Promise.all(saveNotePromises).then(() => resolve(rootNote)) }); |         saxStream.on("end", () => resolve(rootNote)); | ||||||
| 
 | 
 | ||||||
|         const bufferStream = new stream.PassThrough(); |         const bufferStream = new stream.PassThrough(); | ||||||
|         bufferStream.end(file.buffer); |         bufferStream.end(file.buffer); | ||||||
| 
 | 
 | ||||||
|         bufferStream |         bufferStream | ||||||
|             // rate limiting to improve responsiveness during / after import
 |             // rate limiting to improve responsiveness during / after import
 | ||||||
|             .pipe(new Throttle({rate: 300000})) |             .pipe(new Throttle({rate: 500000})) | ||||||
|             .pipe(saxStream); |             .pipe(saxStream); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam