mirror of
https://github.com/zadam/trilium.git
synced 2025-01-14 11:08:02 +08:00
small attribute optimizations
This commit is contained in:
parent
2b4dfaef7f
commit
b0528b62d8
6 changed files with 79 additions and 59 deletions
62
package-lock.json
generated
62
package-lock.json
generated
|
@ -11,10 +11,10 @@
|
|||
"dependencies": {
|
||||
"@braintree/sanitize-url": "6.0.2",
|
||||
"@electron/remote": "2.0.9",
|
||||
"@excalidraw/excalidraw": "0.14.0",
|
||||
"@excalidraw/excalidraw": "0.14.1",
|
||||
"archiver": "5.3.1",
|
||||
"async-mutex": "0.4.0",
|
||||
"axios": "1.2.2",
|
||||
"axios": "1.2.5",
|
||||
"better-sqlite3": "7.4.5",
|
||||
"canvas": "2.11.0",
|
||||
"chokidar": "3.5.3",
|
||||
|
@ -47,7 +47,7 @@
|
|||
"is-svg": "4.3.2",
|
||||
"jimp": "0.16.2",
|
||||
"joplin-turndown-plugin-gfm": "1.0.12",
|
||||
"jsdom": "21.0.0",
|
||||
"jsdom": "21.1.0",
|
||||
"mime-types": "2.1.35",
|
||||
"multer": "1.4.5-lts.1",
|
||||
"node-abi": "3.31.0",
|
||||
|
@ -59,7 +59,6 @@
|
|||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2",
|
||||
"request": "2.88.2",
|
||||
"rimraf": "4.0.4",
|
||||
"safe-compare": "1.1.4",
|
||||
"sanitize-filename": "1.6.3",
|
||||
"sanitize-html": "2.8.1",
|
||||
|
@ -382,9 +381,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@excalidraw/excalidraw": {
|
||||
"version": "0.14.0",
|
||||
"resolved": "https://registry.npmjs.org/@excalidraw/excalidraw/-/excalidraw-0.14.0.tgz",
|
||||
"integrity": "sha512-bQsaS8YFqmy5FF9Dk6QbCXESaU0xAU8JpdhjkQrr9NworPlz+3Ue/Aa2cchVOMMPbGNcYdybYrfWU4TV0mwdag==",
|
||||
"version": "0.14.1",
|
||||
"resolved": "https://registry.npmjs.org/@excalidraw/excalidraw/-/excalidraw-0.14.1.tgz",
|
||||
"integrity": "sha512-npCoKWqC8YeqPXu5+vPqP9bxywFxwv2uJUxieJs94wHPhOH/wV4Nsr6TiTFiXg6DZkrf72iUiLx2hJFA5gCBjw==",
|
||||
"peerDependencies": {
|
||||
"react": "^17.0.2 || ^18.2.0",
|
||||
"react-dom": "^17.0.2 || ^18.2.0"
|
||||
|
@ -1957,9 +1956,9 @@
|
|||
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.2.2.tgz",
|
||||
"integrity": "sha512-bz/J4gS2S3I7mpN/YZfGFTqhXTYzRho8Ay38w2otuuDR322KzFIWm/4W2K6gIwvWaws5n+mnb7D1lN9uD+QH6Q==",
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.2.5.tgz",
|
||||
"integrity": "sha512-9pU/8mmjSSOb4CXVsvGIevN+MlO/t9OWtKadTaLuN85Gge3HGorUckgp8A/2FH4V4hJ7JuQ3LIeI7KAV9ITZrQ==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.0",
|
||||
"form-data": "^4.0.0",
|
||||
|
@ -6722,9 +6721,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/jsdom": {
|
||||
"version": "21.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-21.0.0.tgz",
|
||||
"integrity": "sha512-AIw+3ZakSUtDYvhwPwWHiZsUi3zHugpMEKlNPaurviseYoBqo0zBd3zqoUi3LPCNtPFlEP8FiW9MqCZdjb2IYA==",
|
||||
"version": "21.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-21.1.0.tgz",
|
||||
"integrity": "sha512-m0lzlP7qOtthD918nenK3hdItSd2I+V3W9IrBcB36sqDwG+KnUs66IF5GY7laGWUnlM9vTsD0W1QwSEBYWWcJg==",
|
||||
"dependencies": {
|
||||
"abab": "^2.0.6",
|
||||
"acorn": "^8.8.1",
|
||||
|
@ -8909,20 +8908,6 @@
|
|||
"node": ">= 4"
|
||||
}
|
||||
},
|
||||
"node_modules/rimraf": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.0.4.tgz",
|
||||
"integrity": "sha512-R0hoVr9xTwemarQjoWlNt/nb5dEGVTBhVdkRmEX2zEkT8T6onH0XKiGjuaC7rNNj/gYzY2p4NVRJ3sjO1ascHQ==",
|
||||
"bin": {
|
||||
"rimraf": "dist/cjs/src/bin.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/rndm": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/rndm/-/rndm-1.2.0.tgz",
|
||||
|
@ -11073,9 +11058,9 @@
|
|||
}
|
||||
},
|
||||
"@excalidraw/excalidraw": {
|
||||
"version": "0.14.0",
|
||||
"resolved": "https://registry.npmjs.org/@excalidraw/excalidraw/-/excalidraw-0.14.0.tgz",
|
||||
"integrity": "sha512-bQsaS8YFqmy5FF9Dk6QbCXESaU0xAU8JpdhjkQrr9NworPlz+3Ue/Aa2cchVOMMPbGNcYdybYrfWU4TV0mwdag==",
|
||||
"version": "0.14.1",
|
||||
"resolved": "https://registry.npmjs.org/@excalidraw/excalidraw/-/excalidraw-0.14.1.tgz",
|
||||
"integrity": "sha512-npCoKWqC8YeqPXu5+vPqP9bxywFxwv2uJUxieJs94wHPhOH/wV4Nsr6TiTFiXg6DZkrf72iUiLx2hJFA5gCBjw==",
|
||||
"requires": {}
|
||||
},
|
||||
"@gar/promisify": {
|
||||
|
@ -12361,9 +12346,9 @@
|
|||
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
|
||||
},
|
||||
"axios": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.2.2.tgz",
|
||||
"integrity": "sha512-bz/J4gS2S3I7mpN/YZfGFTqhXTYzRho8Ay38w2otuuDR322KzFIWm/4W2K6gIwvWaws5n+mnb7D1lN9uD+QH6Q==",
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.2.5.tgz",
|
||||
"integrity": "sha512-9pU/8mmjSSOb4CXVsvGIevN+MlO/t9OWtKadTaLuN85Gge3HGorUckgp8A/2FH4V4hJ7JuQ3LIeI7KAV9ITZrQ==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.15.0",
|
||||
"form-data": "^4.0.0",
|
||||
|
@ -16015,9 +16000,9 @@
|
|||
}
|
||||
},
|
||||
"jsdom": {
|
||||
"version": "21.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-21.0.0.tgz",
|
||||
"integrity": "sha512-AIw+3ZakSUtDYvhwPwWHiZsUi3zHugpMEKlNPaurviseYoBqo0zBd3zqoUi3LPCNtPFlEP8FiW9MqCZdjb2IYA==",
|
||||
"version": "21.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-21.1.0.tgz",
|
||||
"integrity": "sha512-m0lzlP7qOtthD918nenK3hdItSd2I+V3W9IrBcB36sqDwG+KnUs66IF5GY7laGWUnlM9vTsD0W1QwSEBYWWcJg==",
|
||||
"requires": {
|
||||
"abab": "^2.0.6",
|
||||
"acorn": "^8.8.1",
|
||||
|
@ -17724,11 +17709,6 @@
|
|||
"resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz",
|
||||
"integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs="
|
||||
},
|
||||
"rimraf": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.0.4.tgz",
|
||||
"integrity": "sha512-R0hoVr9xTwemarQjoWlNt/nb5dEGVTBhVdkRmEX2zEkT8T6onH0XKiGjuaC7rNNj/gYzY2p4NVRJ3sjO1ascHQ=="
|
||||
},
|
||||
"rndm": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/rndm/-/rndm-1.2.0.tgz",
|
||||
|
|
|
@ -29,10 +29,10 @@
|
|||
"dependencies": {
|
||||
"@braintree/sanitize-url": "6.0.2",
|
||||
"@electron/remote": "2.0.9",
|
||||
"@excalidraw/excalidraw": "0.14.0",
|
||||
"@excalidraw/excalidraw": "0.14.1",
|
||||
"archiver": "5.3.1",
|
||||
"async-mutex": "0.4.0",
|
||||
"axios": "1.2.2",
|
||||
"axios": "1.2.5",
|
||||
"better-sqlite3": "7.4.5",
|
||||
"canvas": "2.11.0",
|
||||
"chokidar": "3.5.3",
|
||||
|
@ -65,7 +65,7 @@
|
|||
"is-svg": "4.3.2",
|
||||
"jimp": "0.16.2",
|
||||
"joplin-turndown-plugin-gfm": "1.0.12",
|
||||
"jsdom": "21.0.0",
|
||||
"jsdom": "21.1.0",
|
||||
"mime-types": "2.1.35",
|
||||
"multer": "1.4.5-lts.1",
|
||||
"node-abi": "3.31.0",
|
||||
|
@ -77,7 +77,6 @@
|
|||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2",
|
||||
"request": "2.88.2",
|
||||
"rimraf": "4.0.4",
|
||||
"safe-compare": "1.1.4",
|
||||
"sanitize-filename": "1.6.3",
|
||||
"sanitize-html": "2.8.1",
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue