mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fixed search notes with new treecache
This commit is contained in:
parent
86a330c8c3
commit
e04845335b
@ -854,7 +854,7 @@ async function reloadNotes(noteIds, activateNotePath = null) {
|
|||||||
const node = await getNodeFromPath(activateNotePath);
|
const node = await getNodeFromPath(activateNotePath);
|
||||||
|
|
||||||
if (node) {
|
if (node) {
|
||||||
await node.setActive(true, {noEvents: true}); // this node has been already active so no need to fire events again
|
await node.setActive(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,21 +115,22 @@ async function prepareSearchBranch(note) {
|
|||||||
// force to load all the notes at once instead of one by one
|
// force to load all the notes at once instead of one by one
|
||||||
await treeCache.getNotes(results.map(res => res.noteId));
|
await treeCache.getNotes(results.map(res => res.noteId));
|
||||||
|
|
||||||
for (const result of results) {
|
const {notes, branches} = await server.post('tree/load', { noteIds: [note.noteId] });
|
||||||
const origBranch = treeCache.getBranch(result.branchId);
|
|
||||||
|
|
||||||
const branch = new Branch(treeCache, {
|
results.forEach((result, index) => branches.push({
|
||||||
branchId: "virt" + utils.randomString(10),
|
branchId: "virt" + utils.randomString(10),
|
||||||
noteId: result.noteId,
|
noteId: result.noteId,
|
||||||
parentNoteId: note.noteId,
|
parentNoteId: note.noteId,
|
||||||
prefix: origBranch.prefix,
|
prefix: treeCache.getBranch(result.branchId).prefix,
|
||||||
virtual: true
|
notePosition: (index + 1) * 10
|
||||||
});
|
}));
|
||||||
|
|
||||||
treeCache.addBranch(branch);
|
treeCache.addResp(notes, branches);
|
||||||
}
|
|
||||||
|
|
||||||
return await prepareRealBranch(note);
|
// note in cache changed
|
||||||
|
const newNote = await treeCache.getNote(note.noteId);
|
||||||
|
|
||||||
|
return await prepareRealBranch(newNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getExtraClasses(note) {
|
async function getExtraClasses(note) {
|
||||||
|
@ -5,6 +5,11 @@ import server from "./server.js";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TreeCache keeps a read only cache of note tree structure in frontend's memory.
|
* TreeCache keeps a read only cache of note tree structure in frontend's memory.
|
||||||
|
* - notes are loaded lazily when unknown noteId is requested
|
||||||
|
* - when note is loaded, all its parent and child branches are loaded as well. For a branch to be used, it's not must be loaded before
|
||||||
|
* - deleted notes are present in the cache as well, but they don't have any branches. As a result check for deleted branch is done by presence check - if the branch is not there even though the corresponding note has been loaded, we can infer it is deleted.
|
||||||
|
*
|
||||||
|
* Note and branch deletions are corner cases and usually not needed.
|
||||||
*/
|
*/
|
||||||
class TreeCache {
|
class TreeCache {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -50,12 +55,9 @@ class TreeCache {
|
|||||||
if (childNote) {
|
if (childNote) {
|
||||||
childNote.parents = childNote.parents.filter(p => p !== noteId);
|
childNote.parents = childNote.parents.filter(p => p !== noteId);
|
||||||
|
|
||||||
const branchId = childNote.parentToBranch[noteId];
|
console.log("Cleaning up", childNote.parentToBranch[noteId]);
|
||||||
|
|
||||||
if (branchId in this.branches) {
|
|
||||||
delete this.branches[branchId];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
delete this.branches[childNote.parentToBranch[noteId]];
|
||||||
delete childNote.parentToBranch[noteId];
|
delete childNote.parentToBranch[noteId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,19 +68,18 @@ class TreeCache {
|
|||||||
if (parentNote) {
|
if (parentNote) {
|
||||||
parentNote.children = parentNote.children.filter(p => p !== noteId);
|
parentNote.children = parentNote.children.filter(p => p !== noteId);
|
||||||
|
|
||||||
const branchId = parentNote.childToBranch[noteId];
|
delete this.branches[parentNote.childToBranch[noteId]];
|
||||||
|
|
||||||
if (branchId in this.branches) {
|
|
||||||
delete this.branches[branchId];
|
|
||||||
}
|
|
||||||
|
|
||||||
delete parentNote.childToBranch[noteId];
|
delete parentNote.childToBranch[noteId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const branch of branchesByNotes[noteId] || []) { // can be empty for deleted notes
|
for (const branch of branchesByNotes[noteId] || []) { // can be empty for deleted notes
|
||||||
this.addBranch(branch);
|
if (noteId === '2Ndfjyv3EbEQ') {
|
||||||
|
console.log("Adding", branch.branchId);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.branches[branch.branchId] = branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
const note = new NoteShort(this, noteRow, branchesByNotes[noteId] || []);
|
const note = new NoteShort(this, noteRow, branchesByNotes[noteId] || []);
|
||||||
@ -147,10 +148,6 @@ class TreeCache {
|
|||||||
return (await this.getNotes([noteId], silentNotFoundError))[0];
|
return (await this.getNotes([noteId], silentNotFoundError))[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
addBranch(branch) {
|
|
||||||
this.branches[branch.branchId] = branch;
|
|
||||||
}
|
|
||||||
|
|
||||||
getBranches(branchIds) {
|
getBranches(branchIds) {
|
||||||
return branchIds
|
return branchIds
|
||||||
.map(branchId => this.getBranch(branchId))
|
.map(branchId => this.getBranch(branchId))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user