mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	branches in tree cache should always be loaded if some branchId reference exists
This commit is contained in:
		| @@ -20,7 +20,7 @@ export async function showDialog(node) { | ||||
|     $dialog.modal(); | ||||
|  | ||||
|     branchId = node.data.branchId; | ||||
|     const branch = await treeCache.getBranch(branchId); | ||||
|     const branch = treeCache.getBranch(branchId); | ||||
|  | ||||
|     $treePrefixInput.val(branch.prefix); | ||||
|  | ||||
|   | ||||
| @@ -127,7 +127,7 @@ class NoteShort { | ||||
|     async getChildBranches() { | ||||
|         const branchIds = Object.values(this.childToBranch); | ||||
|  | ||||
|         return await this.treeCache.getBranches(branchIds); | ||||
|         return this.treeCache.getBranches(branchIds); | ||||
|     } | ||||
|  | ||||
|     /** @returns {string[]} */ | ||||
|   | ||||
| @@ -91,7 +91,7 @@ async function showTree() { | ||||
|  | ||||
| $detail.on("click", ".note-menu-button", async e => { | ||||
|     const node = treeService.getActiveNode(); | ||||
|     const branch = await treeCache.getBranch(node.data.branchId); | ||||
|     const branch = treeCache.getBranch(node.data.branchId); | ||||
|     const note = await treeCache.getNote(node.data.noteId); | ||||
|     const parentNote = await treeCache.getNote(branch.parentNoteId); | ||||
|     const isNotRoot = note.noteId !== 'root'; | ||||
|   | ||||
| @@ -24,7 +24,7 @@ async function cloneNoteAfter(noteId, afterBranchId) { | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     const afterBranch = await treeCache.getBranch(afterBranchId); | ||||
|     const afterBranch = treeCache.getBranch(afterBranchId); | ||||
|  | ||||
|     await treeService.reloadNotes([noteId, afterBranch.parentNoteId]); | ||||
| } | ||||
|   | ||||
| @@ -48,7 +48,7 @@ function getActiveNode() { | ||||
| async function getNodesByBranchId(branchId) { | ||||
|     utils.assertArguments(branchId); | ||||
|  | ||||
|     const branch = await treeCache.getBranch(branchId); | ||||
|     const branch = treeCache.getBranch(branchId); | ||||
|  | ||||
|     return getNodesByNoteId(branch.noteId).filter(node => node.data.branchId === branchId); | ||||
| } | ||||
| @@ -64,7 +64,7 @@ function getNodesByNoteId(noteId) { | ||||
| async function setPrefix(branchId, prefix) { | ||||
|     utils.assertArguments(branchId); | ||||
|  | ||||
|     const branch = await treeCache.getBranch(branchId); | ||||
|     const branch = treeCache.getBranch(branchId); | ||||
|  | ||||
|     branch.prefix = prefix; | ||||
|  | ||||
| @@ -75,7 +75,7 @@ async function setPrefix(branchId, prefix) { | ||||
|  | ||||
| async function setNodeTitleWithPrefix(node) { | ||||
|     const noteTitle = await treeUtils.getNoteTitle(node.data.noteId); | ||||
|     const branch = await treeCache.getBranch(node.data.branchId); | ||||
|     const branch = treeCache.getBranch(node.data.branchId); | ||||
|  | ||||
|     const prefix = branch.prefix; | ||||
|  | ||||
| @@ -671,7 +671,7 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) { | ||||
|     noteDetailService.addDetailLoadedListener(note.noteId, noteDetailService.focusAndSelectTitle); | ||||
|  | ||||
|     const noteEntity = await treeCache.getNote(note.noteId); | ||||
|     const branchEntity = await treeCache.getBranch(branch.branchId); | ||||
|     const branchEntity = treeCache.getBranch(branch.branchId); | ||||
|  | ||||
|     let newNode = { | ||||
|         title: newNoteName, | ||||
|   | ||||
| @@ -11,7 +11,7 @@ async function prepareTree() { | ||||
|     let hoistedBranch; | ||||
|  | ||||
|     if (hoistedNoteId === 'root') { | ||||
|         hoistedBranch = await treeCache.getBranch('root'); | ||||
|         hoistedBranch = treeCache.getBranch('root'); | ||||
|     } | ||||
|     else { | ||||
|         const hoistedNote = await treeCache.getNote(hoistedNoteId); | ||||
| @@ -116,7 +116,7 @@ async function prepareSearchBranch(note) { | ||||
|     await treeCache.getNotes(results.map(res => res.noteId)); | ||||
|  | ||||
|     for (const result of results) { | ||||
|         const origBranch = await treeCache.getBranch(result.branchId); | ||||
|         const origBranch = treeCache.getBranch(result.branchId); | ||||
|  | ||||
|         const branch = new Branch(treeCache, { | ||||
|             branchId: "virt" + utils.randomString(10), | ||||
|   | ||||
| @@ -1,4 +1,3 @@ | ||||
| import utils from "./utils.js"; | ||||
| import Branch from "../entities/branch.js"; | ||||
| import NoteShort from "../entities/note_short.js"; | ||||
| import ws from "./ws.js"; | ||||
| @@ -151,29 +150,20 @@ class TreeCache { | ||||
|         this.branches[branch.branchId] = branch; | ||||
|     } | ||||
|  | ||||
|     async getBranches(branchIds) { | ||||
|         const missingBranchIds = branchIds.filter(branchId => this.branches[branchId] === undefined); | ||||
|  | ||||
|         if (missingBranchIds.length > 0) { | ||||
|             const resp = await server.post('tree/load', { branchIds: branchIds }); | ||||
|  | ||||
|             this.addResp(resp.notes, resp.branches); | ||||
|     getBranches(branchIds) { | ||||
|         return branchIds | ||||
|             .map(branchId => this.getBranch(branchId)) | ||||
|             .filter(b => b !== null); | ||||
|     } | ||||
|  | ||||
|         return branchIds.map(branchId => { | ||||
|             if (!this.branches[branchId]) { | ||||
|                 throw new Error(`Can't find branch ${branchId}`); | ||||
|     /** @return {Branch} */ | ||||
|     getBranch(branchId) { | ||||
|         if (!(branchId in this.branches)) { | ||||
|             console.error(`Not existing branch ${branchId}`); | ||||
|         } | ||||
|             else { | ||||
|  | ||||
|         return this.branches[branchId]; | ||||
|     } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     /** @return Branch */ | ||||
|     async getBranch(branchId) { | ||||
|         return (await this.getBranches([branchId]))[0]; | ||||
|     } | ||||
| } | ||||
|  | ||||
| const treeCache = new TreeCache(); | ||||
|   | ||||
| @@ -26,7 +26,7 @@ class TreeContextMenu { | ||||
|     } | ||||
|  | ||||
|     async getContextMenuItems() { | ||||
|         const branch = await treeCache.getBranch(this.node.data.branchId); | ||||
|         const branch = treeCache.getBranch(this.node.data.branchId); | ||||
|         const note = await treeCache.getNote(this.node.data.noteId); | ||||
|         const parentNote = await treeCache.getNote(branch.parentNoteId); | ||||
|         const isNotRoot = note.noteId !== 'root'; | ||||
| @@ -156,7 +156,7 @@ class TreeContextMenu { | ||||
|             hoistedNoteService.unhoist(); | ||||
|         } | ||||
|         else if (cmd === "duplicateNote") { | ||||
|             const branch = await treeCache.getBranch(this.node.data.branchId); | ||||
|             const branch = treeCache.getBranch(this.node.data.branchId); | ||||
|  | ||||
|             treeService.duplicateNote(this.node.data.noteId, branch.parentNoteId); | ||||
|         } | ||||
|   | ||||
| @@ -62,7 +62,7 @@ async function getNoteTitle(noteId, parentNoteId = null) { | ||||
|         const branchId = note.parentToBranch[parentNoteId]; | ||||
|  | ||||
|         if (branchId) { | ||||
|             const branch = await treeCache.getBranch(branchId); | ||||
|             const branch = treeCache.getBranch(branchId); | ||||
|  | ||||
|             if (branch && branch.prefix) { | ||||
|                 title = branch.prefix + ' - ' + title; | ||||
|   | ||||
| @@ -99,15 +99,7 @@ async function getTree() { | ||||
| } | ||||
|  | ||||
| async function load(req) { | ||||
|     let noteIds = req.body.noteIds; | ||||
|     const branchIds = req.body.branchIds; | ||||
|  | ||||
|     if (branchIds && branchIds.length > 0) { | ||||
|         noteIds = (await sql.getManyRows(`SELECT noteId FROM branches WHERE isDeleted = 0 AND branchId IN(???)`, branchIds)) | ||||
|             .map(note => note.noteId); | ||||
|     } | ||||
|  | ||||
|     return await getNotesAndBranches(noteIds); | ||||
|     return await getNotesAndBranches(req.body.noteIds); | ||||
| } | ||||
|  | ||||
| module.exports = { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user