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