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
sync fixes
zadameb4dfbad9268
diff --git a/src/public/javascripts/services/tree_builder.js b/src/public/javascripts/services/tree_builder.jsindex 70522af7ca..eda30b55aa 100644--- a/src/public/javascripts/services/tree_builder.js+++ b/src/public/javascripts/services/tree_builder.js@@ -67,7 +67,7 @@ async function prepareNode(branch) {const note = await branch.getNote();if (!note) {- console.log(`Branch has no note: ${branch}`);+ throw new Error(`Branch has no note ` + branch.noteId);}const title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title;diff --git a/src/public/javascripts/services/ws.js b/src/public/javascripts/services/ws.jsindex b6bb40882f..918ab8aeec 100644--- a/src/public/javascripts/services/ws.js+++ b/src/public/javascripts/services/ws.js@@ -59,6 +59,10 @@ async function handleMessage(event) {syncDataQueue.push(...syncRows);+ // we set lastAcceptedSyncId even before sync processing and send ping so that backend can start sending more updates+ lastAcceptedSyncId = Math.max(lastAcceptedSyncId, syncRows[syncRows.length - 1].id);+ sendPing();+// first wait for all the preceding consumers to finishwhile (consumeQueuePromise) {await consumeQueuePromise;@@ -132,15 +136,19 @@ async function consumeSyncData() {const outsideSyncData = allSyncData.filter(sync => sync.sourceId !== glob.sourceId);- // we set lastAcceptedSyncId even before sync processing and send ping so that backend can start sending more updates- lastAcceptedSyncId = Math.max(lastAcceptedSyncId, allSyncData[allSyncData.length - 1].id);- sendPing();+ try {+ // the update process should be synchronous as a whole but individual handlers can run in parallel+ await Promise.all([+ ...allSyncMessageHandlers.map(syncHandler => runSafely(syncHandler, allSyncData)),+ ...outsideSyncMessageHandlers.map(syncHandler => runSafely(syncHandler, outsideSyncData))+ ]);+ }+ catch (e) {+ logError(`Encountered error ${e.message}, reloading frontend.`);- // the update process should be synchronous as a whole but individual handlers can run in parallel- await Promise.all([- ...allSyncMessageHandlers.map(syncHandler => runSafely(syncHandler, allSyncData)),- ...outsideSyncMessageHandlers.map(syncHandler => runSafely(syncHandler, outsideSyncData))- ]);+ // if there's an error in updating the frontend then the easy option to recover is to reload the frontend completely+ utils.reloadApp();+ }lastProcessedSyncId = Math.max(lastProcessedSyncId, allSyncData[allSyncData.length - 1].id);}