mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	tree cache reloading
This commit is contained in:
		| @@ -110,12 +110,7 @@ async function expandToNote(notePath, expandOpts) { | |||||||
|             let node = getNode(childNoteId, parentNoteId); |             let node = getNode(childNoteId, parentNoteId); | ||||||
|  |  | ||||||
|             if (!node && parentNoteId) { |             if (!node && parentNoteId) { | ||||||
|                 const parents = getNodesByNoteId(parentNoteId); |                 await reloadNote(parentNoteId); | ||||||
|  |  | ||||||
|                 for (const parent of parents) { |  | ||||||
|                     // force load parents. This is useful when fancytree doesn't contain recently created notes yet. |  | ||||||
|                     await parent.load(true); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 node = getNode(childNoteId, parentNoteId); |                 node = getNode(childNoteId, parentNoteId); | ||||||
|             } |             } | ||||||
| @@ -371,17 +366,23 @@ async function treeInitialized() { | |||||||
|  |  | ||||||
|     const noteId = treeUtils.getNoteIdFromNotePath(startNotePath); |     const noteId = treeUtils.getNoteIdFromNotePath(startNotePath); | ||||||
|  |  | ||||||
|     if (!await treeCache.getNote(noteId)) { |     if (!await treeCache.noteExists(noteId)) { | ||||||
|         // note doesn't exist so don't try to activate it |         // note doesn't exist so don't try to activate it | ||||||
|         startNotePath = null; |         startNotePath = null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (startNotePath) { |     if (startNotePath) { | ||||||
|         const node = await activateNote(startNotePath); |         // this is weird but it looks like even though init event has been called, but we the tree still | ||||||
|  |         // can't find nodes for given path which causes double loading of data. Little timeout fixes this. | ||||||
|  |         setTimeout(async () => { | ||||||
|  |             console.log("activating ", startNotePath); | ||||||
|  |  | ||||||
|         // looks like this this doesn't work when triggered immediatelly after activating node |             const node = await activateNote(startNotePath); | ||||||
|         // so waiting a second helps |  | ||||||
|         setTimeout(() => node.makeVisible({scrollIntoView: true}), 1000); |             // looks like this this doesn't work when triggered immediatelly after activating node | ||||||
|  |             // so waiting a second helps | ||||||
|  |             setTimeout(() => node.makeVisible({scrollIntoView: true}), 1000); | ||||||
|  |         }, 100); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -760,6 +761,8 @@ async function checkFolderStatus(node) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function reloadNote(noteId) { | async function reloadNote(noteId) { | ||||||
|  |     await treeCache.reload(noteId); | ||||||
|  |  | ||||||
|     for (const node of getNodesByNoteId(noteId)) { |     for (const node of getNodesByNoteId(noteId)) { | ||||||
|         await node.load(true); |         await node.load(true); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -17,8 +17,12 @@ class TreeCache { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     init() { |     init() { | ||||||
|  |         /** @type {Object.<string, string>} */ | ||||||
|         this.parents = {}; |         this.parents = {}; | ||||||
|  |         /** @type {Object.<string, string>} */ | ||||||
|         this.children = {}; |         this.children = {}; | ||||||
|  |  | ||||||
|  |         /** @type {Object.<string, string>} */ | ||||||
|         this.childParentToBranch = {}; |         this.childParentToBranch = {}; | ||||||
|  |  | ||||||
|         /** @type {Object.<string, NoteShort>} */ |         /** @type {Object.<string, NoteShort>} */ | ||||||
| @@ -46,6 +50,26 @@ class TreeCache { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     async reload(noteId) { | ||||||
|  |         const resp = await server.post('tree/load', { noteIds: [noteId] }); | ||||||
|  |  | ||||||
|  |         for (const childNoteId of this.children[noteId] || []) { | ||||||
|  |             this.parents[childNoteId] = this.parents[childNoteId].filter(p => p !== noteId); | ||||||
|  |  | ||||||
|  |             const branchId = this.getBranchIdByChildParent(childNoteId, noteId); | ||||||
|  |  | ||||||
|  |             delete this.branches[branchId]; | ||||||
|  |             delete this.childParentToBranch[childNoteId + '-' + noteId]; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         this.children[noteId] = []; | ||||||
|  |  | ||||||
|  |         delete this.notes[noteId]; | ||||||
|  |  | ||||||
|  |         this.addResp(resp.notes, resp.branches, resp.relations); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** @return {Promise<NoteShort[]>} */ | ||||||
|     async getNotes(noteIds, silentNotFoundError = false) { |     async getNotes(noteIds, silentNotFoundError = false) { | ||||||
|         const missingNoteIds = noteIds.filter(noteId => this.notes[noteId] === undefined); |         const missingNoteIds = noteIds.filter(noteId => this.notes[noteId] === undefined); | ||||||
|  |  | ||||||
| @@ -67,7 +91,14 @@ class TreeCache { | |||||||
|         }).filter(note => note !== null); |         }).filter(note => note !== null); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** @return NoteShort */ |     /** @return {Promise<boolean>} */ | ||||||
|  |     async noteExists(noteId) { | ||||||
|  |         const notes = await this.getNotes([noteId], true); | ||||||
|  |  | ||||||
|  |         return notes.length === 1; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** @return {Promise<NoteShort>} */ | ||||||
|     async getNote(noteId) { |     async getNote(noteId) { | ||||||
|         if (noteId === 'none') { |         if (noteId === 'none') { | ||||||
|             return null; |             return null; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user