mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-30 20:41:33 +08:00 
			
		
		
		
	properly handle saved search virtual branches during reloads, fixes #1301
This commit is contained in:
		
							parent
							
								
									a9f49e7f25
								
							
						
					
					
						commit
						00d860bfae
					
				
							
								
								
									
										20
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										20
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -3095,9 +3095,9 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "electron-rebuild": { |     "electron-rebuild": { | ||||||
|       "version": "2.2.0", |       "version": "2.3.0", | ||||||
|       "resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-2.2.0.tgz", |       "resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-2.3.0.tgz", | ||||||
|       "integrity": "sha512-qbrCoBSmbL/f6OwfRXg5cihAJ0TwbgRKmyK7helR6XNlaoPO42ny/+4yCTXJrYa0ZhkvcdY+gZE/wu2p19gFHg==", |       "integrity": "sha512-+2H3xFc9aFFmMcYP6AOYBcY1gJd+aYlglBBXUnkyXd0ZAqM9y6LWND4UEBPncVTAJ2q6neKLPR7RLceIxgyukA==", | ||||||
|       "dev": true, |       "dev": true, | ||||||
|       "requires": { |       "requires": { | ||||||
|         "@malept/cross-spawn-promise": "^1.1.0", |         "@malept/cross-spawn-promise": "^1.1.0", | ||||||
| @ -3115,9 +3115,9 @@ | |||||||
|       }, |       }, | ||||||
|       "dependencies": { |       "dependencies": { | ||||||
|         "@sindresorhus/is": { |         "@sindresorhus/is": { | ||||||
|           "version": "3.1.2", |           "version": "4.0.0", | ||||||
|           "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-3.1.2.tgz", |           "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.0.0.tgz", | ||||||
|           "integrity": "sha512-JiX9vxoKMmu8Y3Zr2RVathBL1Cdu4Nt4MuNWemt1Nc06A0RAin9c5FArkhGsyMBWfCu4zj+9b+GxtjAnE4qqLQ==", |           "integrity": "sha512-FyD2meJpDPjyNQejSjvnhpgI/azsQkA4lGbuu5BQZfjvJ9cbRZXzeWL2HceCekW4lixO9JPesIIQkSoLjeJHNQ==", | ||||||
|           "dev": true |           "dev": true | ||||||
|         }, |         }, | ||||||
|         "@szmarczak/http-timer": { |         "@szmarczak/http-timer": { | ||||||
| @ -3169,12 +3169,12 @@ | |||||||
|           } |           } | ||||||
|         }, |         }, | ||||||
|         "got": { |         "got": { | ||||||
|           "version": "11.7.0", |           "version": "11.8.0", | ||||||
|           "resolved": "https://registry.npmjs.org/got/-/got-11.7.0.tgz", |           "resolved": "https://registry.npmjs.org/got/-/got-11.8.0.tgz", | ||||||
|           "integrity": "sha512-7en2XwH2MEqOsrK0xaKhbWibBoZqy+f1RSUoIeF1BLcnf+pyQdDsljWMfmOh+QKJwuvDIiKx38GtPh5wFdGGjg==", |           "integrity": "sha512-k9noyoIIY9EejuhaBNLyZ31D5328LeqnyPNXJQb2XlJZcKakLqN5m6O/ikhq/0lw56kUYS54fVm+D1x57YC9oQ==", | ||||||
|           "dev": true, |           "dev": true, | ||||||
|           "requires": { |           "requires": { | ||||||
|             "@sindresorhus/is": "^3.1.1", |             "@sindresorhus/is": "^4.0.0", | ||||||
|             "@szmarczak/http-timer": "^4.0.5", |             "@szmarczak/http-timer": "^4.0.5", | ||||||
|             "@types/cacheable-request": "^6.0.1", |             "@types/cacheable-request": "^6.0.1", | ||||||
|             "@types/responselike": "^1.0.0", |             "@types/responselike": "^1.0.0", | ||||||
|  | |||||||
| @ -80,7 +80,7 @@ | |||||||
|     "electron": "9.3.2", |     "electron": "9.3.2", | ||||||
|     "electron-builder": "22.9.1", |     "electron-builder": "22.9.1", | ||||||
|     "electron-packager": "15.1.0", |     "electron-packager": "15.1.0", | ||||||
|     "electron-rebuild": "2.2.0", |     "electron-rebuild": "2.3.0", | ||||||
|     "esm": "3.2.25", |     "esm": "3.2.25", | ||||||
|     "jasmine": "3.6.2", |     "jasmine": "3.6.2", | ||||||
|     "jsdoc": "3.6.6", |     "jsdoc": "3.6.6", | ||||||
|  | |||||||
| @ -21,6 +21,8 @@ class Branch { | |||||||
|         this.isExpanded = !!row.isExpanded; |         this.isExpanded = !!row.isExpanded; | ||||||
|         /** @param {boolean} */ |         /** @param {boolean} */ | ||||||
|         this.isDeleted = !!row.isDeleted; |         this.isDeleted = !!row.isDeleted; | ||||||
|  |         /** @param {boolean} */ | ||||||
|  |         this.fromSearchNote = !!row.fromSearchNote; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** @returns {NoteShort} */ |     /** @returns {NoteShort} */ | ||||||
|  | |||||||
| @ -85,10 +85,14 @@ class TreeCache { | |||||||
|         for (const noteRow of noteRows) { |         for (const noteRow of noteRows) { | ||||||
|             const {noteId} = noteRow; |             const {noteId} = noteRow; | ||||||
| 
 | 
 | ||||||
|             const oldNote = this.notes[noteId]; |             let note = this.notes[noteId]; | ||||||
| 
 | 
 | ||||||
|             if (oldNote) { |             if (note) { | ||||||
|                 for (const childNoteId of oldNote.children) { |                 note.update(noteRow); | ||||||
|  | 
 | ||||||
|  |                 // search note doesn't have child branches in database and all the children are virtual branches
 | ||||||
|  |                 if (note.type !== 'search') { | ||||||
|  |                     for (const childNoteId of note.children) { | ||||||
|                         const childNote = this.notes[childNoteId]; |                         const childNote = this.notes[childNoteId]; | ||||||
| 
 | 
 | ||||||
|                         if (childNote) { |                         if (childNote) { | ||||||
| @ -99,21 +103,35 @@ class TreeCache { | |||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                 for (const parentNoteId of oldNote.parents) { |                     note.children = []; | ||||||
|                     const parentNote = this.notes[parentNoteId]; |                     note.childToBranch = []; | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 // we want to remove all "real" branches (represented in the database) since those will be created
 | ||||||
|  |                 // from branches argument but want to preserve all virtual ones from saved search
 | ||||||
|  |                 note.parents = note.parents.filter(parentNoteId => { | ||||||
|  |                     const parentNote = this.notes[parentNoteId]; | ||||||
|  |                     const branch = this.branches[parentNote.childToBranch[noteId]]; | ||||||
|  | 
 | ||||||
|  |                     if (!parentNote || !branch) { | ||||||
|  |                         return false; | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|  |                     if (branch.fromSearchNote) { | ||||||
|  |                         return true; | ||||||
|  |                     } | ||||||
| 
 | 
 | ||||||
|                     if (parentNote) { |  | ||||||
|                     parentNote.children = parentNote.children.filter(p => p !== noteId); |                     parentNote.children = parentNote.children.filter(p => p !== noteId); | ||||||
| 
 | 
 | ||||||
|                     delete this.branches[parentNote.childToBranch[noteId]]; |                     delete this.branches[parentNote.childToBranch[noteId]]; | ||||||
|                     delete parentNote.childToBranch[noteId]; |                     delete parentNote.childToBranch[noteId]; | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             const note = new NoteShort(this, noteRow); |                     return false; | ||||||
| 
 |                 }); | ||||||
|             this.notes[note.noteId] = note; |             } | ||||||
|  |             else { | ||||||
|  |                 this.notes[noteId] = new NoteShort(this, noteRow); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         for (const branchRow of branchRows) { |         for (const branchRow of branchRows) { | ||||||
| @ -187,7 +205,8 @@ class TreeCache { | |||||||
|                     branchId: "virt" + resultNoteId + '-' + note.noteId, |                     branchId: "virt" + resultNoteId + '-' + note.noteId, | ||||||
|                     noteId: resultNoteId, |                     noteId: resultNoteId, | ||||||
|                     parentNoteId: note.noteId, |                     parentNoteId: note.noteId, | ||||||
|                     notePosition: (index + 1) * 10 |                     notePosition: (index + 1) * 10, | ||||||
|  |                     fromSearchNote: true | ||||||
|                 })); |                 })); | ||||||
| 
 | 
 | ||||||
|                 // update this note with standard (parent) branches + virtual (children) branches
 |                 // update this note with standard (parent) branches + virtual (children) branches
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam