mirror of
https://github.com/zadam/trilium.git
synced 2025-11-10 15:25:51 +01:00
small attribute optimizations
This commit is contained in:
@@ -747,8 +747,15 @@ class BNote extends AbstractBeccaEntity {
|
||||
// will sort the parents so that the non-archived are first and archived at the end
|
||||
// this is done so that the non-archived paths are always explored as first when looking for note path
|
||||
sortParents() {
|
||||
this.parentBranches.sort((a, b) =>
|
||||
a.parentNote?.hasInheritableArchivedLabel() ? 1 : -1);
|
||||
this.parentBranches.sort((a, b) => {
|
||||
if (a.parentNote?.isArchived) {
|
||||
return 1;
|
||||
} else if (a.parentNote?.isHiddenCompletely()) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
|
||||
this.parents = this.parentBranches
|
||||
.map(branch => branch.parentNote)
|
||||
@@ -1166,7 +1173,23 @@ class BNote extends AbstractBeccaEntity {
|
||||
* @return boolean - true if there's no non-hidden path, note is not cloned to the visible tree
|
||||
*/
|
||||
isHiddenCompletely() {
|
||||
return !this.getAllNotePaths().find(notePathArr => !notePathArr.includes('_hidden'));
|
||||
if (this.noteId === 'root') {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const parentNote of this.parents) {
|
||||
if (parentNote.noteId === 'root') {
|
||||
return false;
|
||||
} else if (parentNote.noteId === '_hidden') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!parentNote.isHiddenCompletely()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -199,7 +199,7 @@ class FNote {
|
||||
|
||||
const aNote = this.froca.getNoteFromCache([aNoteId]);
|
||||
|
||||
if (aNote.hasLabel('archived')) {
|
||||
if (aNote.isArchived || aNote.isHiddenCompletely()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -207,6 +207,10 @@ class FNote {
|
||||
});
|
||||
}
|
||||
|
||||
get isArchived() {
|
||||
return this.hasAttribute('label', 'archived');
|
||||
}
|
||||
|
||||
/** @returns {string[]} */
|
||||
getChildNoteIds() {
|
||||
return this.children;
|
||||
@@ -338,7 +342,7 @@ class FNote {
|
||||
const notePaths = this.getAllNotePaths().map(path => ({
|
||||
notePath: path,
|
||||
isInHoistedSubTree: path.includes(hoistedNotePath),
|
||||
isArchived: path.find(noteId => froca.notes[noteId].hasLabel('archived')),
|
||||
isArchived: path.find(noteId => froca.notes[noteId].isArchived),
|
||||
isSearch: path.find(noteId => froca.notes[noteId].type === 'search'),
|
||||
isHidden: path.includes('_hidden')
|
||||
}));
|
||||
@@ -364,7 +368,23 @@ class FNote {
|
||||
* @return boolean - true if there's no non-hidden path, note is not cloned to the visible tree
|
||||
*/
|
||||
isHiddenCompletely() {
|
||||
return !this.getAllNotePaths().find(notePathArr => !notePathArr.includes('_hidden'));
|
||||
if (this.noteId === 'root') {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const parentNote of this.getParentNotes()) {
|
||||
if (parentNote.noteId === 'root') {
|
||||
return false;
|
||||
} else if (parentNote.noteId === '_hidden') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!parentNote.isHiddenCompletely()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
__filterAttrs(attributes, type, name) {
|
||||
@@ -521,9 +541,9 @@ class FNote {
|
||||
* @returns {FAttribute} attribute of given type and name. If there's more such attributes, first is returned. Returns null if there's no such attribute belonging to this note.
|
||||
*/
|
||||
getOwnedAttribute(type, name) {
|
||||
const attributes = this.getOwnedAttributes(type, name);
|
||||
const attributes = this.getOwnedAttributes();
|
||||
|
||||
return attributes.length > 0 ? attributes[0] : 0;
|
||||
return attributes.find(attr => attr.name === name && attr.type === type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -532,9 +552,9 @@ class FNote {
|
||||
* @returns {FAttribute} attribute of given type and name. If there's more such attributes, first is returned. Returns null if there's no such attribute belonging to this note.
|
||||
*/
|
||||
getAttribute(type, name) {
|
||||
const attributes = this.getAttributes(type, name);
|
||||
const attributes = this.getAttributes();
|
||||
|
||||
return attributes.length > 0 ? attributes[0] : null;
|
||||
return attributes.find(attr => attr.name === name && attr.type === type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,9 +35,7 @@ async function isHoistedInHiddenSubtree() {
|
||||
}
|
||||
|
||||
const hoistedNote = await froca.getNote(hoistedNoteId);
|
||||
const hoistedNotePath = treeService.getSomeNotePath(hoistedNote);
|
||||
|
||||
return treeService.isNotePathInHiddenSubtree(hoistedNotePath);
|
||||
return hoistedNote.isHiddenCompletely();
|
||||
}
|
||||
|
||||
async function checkNoteAccess(notePath, noteContext) {
|
||||
|
||||
@@ -20,7 +20,7 @@ function isHoistedInHiddenSubtree() {
|
||||
throw new Error(`Cannot find hoisted note ${hoistedNoteId}`);
|
||||
}
|
||||
|
||||
return hoistedNote.hasAncestor('_hidden');
|
||||
return hoistedNote.isHiddenCompletely();
|
||||
}
|
||||
|
||||
function getHoistedNote() {
|
||||
|
||||
Reference in New Issue
Block a user