Skip to content

Build your personal knowledge base with Trilium Notes

optimized custom script/widget loading

zadam16d97b95afaf
diff --git a/package-lock.json b/package-lock.json
index 273e40ec06..72884acc0a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1468,20 +1468,20 @@
"integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw=="
},
"body-parser": {
- "version": "1.19.0",
- "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
- "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==",
+ "version": "1.19.1",
+ "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.1.tgz",
+ "integrity": "sha512-8ljfQi5eBk8EJfECMrgqNGWPEY5jWP+1IzkzkGdFFEwFQZZyaZ21UqdaHktgiMlH0xLHqIFtE/u2OYE5dOtViA==",
"requires": {
- "bytes": "3.1.0",
+ "bytes": "3.1.1",
"content-type": "~1.0.4",
"debug": "2.6.9",
"depd": "~1.1.2",
- "http-errors": "1.7.2",
+ "http-errors": "1.8.1",
"iconv-lite": "0.4.24",
"on-finished": "~2.3.0",
- "qs": "6.7.0",
- "raw-body": "2.4.0",
- "type-is": "~1.6.17"
+ "qs": "6.9.6",
+ "raw-body": "2.4.2",
+ "type-is": "~1.6.18"
},
"dependencies": {
"debug": {
@@ -1831,9 +1831,9 @@
}
},
"bytes": {
- "version": "3.1.0",
- "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
- "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
+ "version": "3.1.1",
+ "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.1.tgz",
+ "integrity": "sha512-dWe4nWO/ruEOY7HkUJ5gFt1DCFV9zPRoJr8pV0/ASQermOZjtq8jMjOprC0Kd10GLN+l7xaUPvxzJFWtxGu8Fg=="
},
"cacache": {
"version": "15.3.0",
@@ -4772,15 +4772,32 @@
"dev": true
},
"http-errors": {
- "version": "1.7.2",
- "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
- "integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==",
+ "version": "1.8.1",
+ "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz",
+ "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==",
"requires": {
"depd": "~1.1.2",
- "inherits": "2.0.3",
- "setprototypeof": "1.1.1",
+ "inherits": "2.0.4",
+ "setprototypeof": "1.2.0",
"statuses": ">= 1.5.0 < 2",
- "toidentifier": "1.0.0"
+ "toidentifier": "1.0.1"
+ },
+ "dependencies": {
+ "inherits": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
+ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
+ },
+ "setprototypeof": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
+ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="
+ },
+ "toidentifier": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
+ "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="
+ }
}
},
"http-proxy-agent": {
@@ -6595,9 +6612,9 @@
}
},
"postcss": {
- "version": "8.4.0",
- "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.0.tgz",
- "integrity": "sha512-BRMNx3Wy7UI89jN8H4ZVS5lQMPM2OSMkOkvDCSjwXa7PWTs24k7Lm55NXLbMbs070LvraXaxN5l1npSOS6wMVw==",
+ "version": "8.4.5",
+ "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.5.tgz",
+ "integrity": "sha512-jBDboWM8qpaqwkMwItqTQTiFikhs/67OYVvblFFTM7MrZjt6yMKd6r2kgXizEbTTljacm4NldIlZnhbjr84QYg==",
"requires": {
"nanoid": "^3.1.30",
"picocolors": "^1.0.0",
@@ -6716,9 +6733,9 @@
}
},
"qs": {
- "version": "6.7.0",
- "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
- "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ=="
+ "version": "6.9.6",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.6.tgz",
+ "integrity": "sha512-TIRk4aqYLNoJUbd+g2lEdz5kLWIuTMRagAXxl78Q0RiVjAOugHmeKNGdd3cwo/ktpf9aL9epCfFqWDEKysUlLQ=="
},
"quick-lru": {
"version": "5.1.1",
@@ -6751,12 +6768,12 @@
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg=="
},
"raw-body": {
- "version": "2.4.0",
- "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz",
- "integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==",
+ "version": "2.4.2",
+ "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.2.tgz",
+ "integrity": "sha512-RPMAFUJP19WIet/99ngh6Iv8fzAbqum4Li7AD6DtGaW2RpMB/11xDoalPiJMTbu6I3hkbMVkATvZrqb9EEqeeQ==",
"requires": {
- "bytes": "3.1.0",
- "http-errors": "1.7.2",
+ "bytes": "3.1.1",
+ "http-errors": "1.8.1",
"iconv-lite": "0.4.24",
"unpipe": "1.0.0"
}
@@ -7068,9 +7085,9 @@
}
},
"sanitize-html": {
- "version": "2.6.0",
- "resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-2.6.0.tgz",
- "integrity": "sha512-qc+NqTeaOi/QVAVs5gOY9tqIVk4r1pcUbx1Q2N1a609Os3TNlm85zll2d8g8m/RM6RWg9llir0SpAcePQVIC1w==",
+ "version": "2.6.1",
+ "resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-2.6.1.tgz",
+ "integrity": "sha512-DzjSz3H5qDntD7s1TcWCSoRPmNR8UmA+y+xZQOvWgjATe2Br9ZW73+vD3Pj6Snrg0RuEuJdXgrKvnYuiuixRkA==",
"requires": {
"deepmerge": "^4.2.2",
"escape-string-regexp": "^4.0.0",
diff --git a/package.json b/package.json
index 03f3851be9..c1f4da7216 100644
--- a/package.json
+++ b/package.json
@@ -28,7 +28,7 @@
"async-mutex": "0.3.2",
"axios": "0.24.0",
"better-sqlite3": "7.4.5",
- "body-parser": "1.19.0",
+ "body-parser": "1.19.1",
"chokidar": "3.5.2",
"cls-hooked": "4.2.2",
"commonmark": "0.30.0",
@@ -67,7 +67,7 @@
"request": "^2.88.2",
"rimraf": "3.0.2",
"sanitize-filename": "1.6.3",
- "sanitize-html": "2.6.0",
+ "sanitize-html": "2.6.1",
"sax": "1.2.4",
"semver": "7.3.5",
"serve-favicon": "2.5.0",
diff --git a/src/routes/api/script.js b/src/routes/api/script.js
index b591307df9..2f2aa879fa 100644
--- a/src/routes/api/script.js
+++ b/src/routes/api/script.js
@@ -38,7 +38,7 @@ function run(req) {
}
function getBundlesWithLabel(label, value) {
- const notes = attributeService.getNotesWithLabel(label, value);
+ const notes = attributeService.getNotesWithLabelFast(label, value);
const bundles = [];
diff --git a/src/services/attributes.js b/src/services/attributes.js
index eb5484fdcd..302cab1ecb 100644
--- a/src/services/attributes.js
+++ b/src/services/attributes.js
@@ -95,6 +95,24 @@ function getNoteWithLabel(name, value) {
return null;
}
+/**
+ * Does not take into account templates and inheritance
+ */
+function getNotesWithLabelFast(name, value) {
+ // optimized version (~20 times faster) without using normal search, useful for e.g. finding date notes
+ const attrs = becca.findAttributes('label', name);
+
+ if (value === undefined) {
+ return attrs.map(attr => attr.getNote());
+ }
+
+ value = value?.toLowerCase();
+
+ return attrs
+ .filter(attr => attr.value.toLowerCase() === value)
+ .map(attr => attr.getNote());
+}
+
function createLabel(noteId, name, value = "") {
return createAttribute({
noteId: noteId,
@@ -186,6 +204,7 @@ function sanitizeAttributeName(origName) {
module.exports = {
getNotesWithLabel,
+ getNotesWithLabelFast,
getNoteWithLabel,
createLabel,
createRelation,