Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
runOnNoteChange fires also on the frontend, closes #340
azivner19d8947123a9
diff --git a/src/public/javascripts/services/bundle.js b/src/public/javascripts/services/bundle.jsindex 2f6f6bd871..4d67496baa 100644--- a/src/public/javascripts/services/bundle.js+++ b/src/public/javascripts/services/bundle.js@@ -30,9 +30,13 @@ async function executeStartupBundles() {}async function executeRelationBundles(note, relationName) {- const bundlesToRun = await server.get("script/relation/" + note.noteId + "/" + relationName);+ note.bundleCache = note.bundleCache || {};- for (const bundle of bundlesToRun) {+ if (!note.bundleCache[relationName]) {+ note.bundleCache[relationName] = await server.get("script/relation/" + note.noteId + "/" + relationName);+ }++ for (const bundle of note.bundleCache[relationName]) {await executeBundle(bundle, note);}}diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.jsindex 07e3057f32..4f750b99b2 100644--- a/src/public/javascripts/services/note_detail.js+++ b/src/public/javascripts/services/note_detail.js@@ -131,6 +131,9 @@ async function saveNote() {}$savedIndicator.fadeIn();++ // run async+ bundleService.executeRelationBundles(getCurrentNote(), 'runOnNoteChange');}async function saveNoteIfChanged() {diff --git a/src/routes/api/script.js b/src/routes/api/script.jsindex 87927e612b..72ca8ec921 100644--- a/src/routes/api/script.js+++ b/src/routes/api/script.js@@ -54,6 +54,11 @@ async function getRelationBundles(req) {for (const noteId of uniqueNoteIds) {const note = await repository.getNote(noteId);++ if (!note.isJavaScript() || note.getScriptEnv() !== 'frontend') {+ continue;+ }+const bundle = await scriptService.getScriptBundleForFrontend(note);if (bundle) {diff --git a/src/services/script.js b/src/services/script.jsindex 2c3a7855ef..628510c6d3 100644--- a/src/services/script.js+++ b/src/services/script.js@@ -6,7 +6,7 @@ const sourceIdService = require('./source_id');const log = require('./log');async function executeNote(note, originEntity) {- if (!note.isJavaScript() || !note.isContentAvailable) {+ if (!note.isJavaScript() || note.getScriptEnv() !== 'backend' || !note.isContentAvailable) {return;}