Skip to content

Build your personal knowledge base with Trilium Notes

add time limit to frontend update

zadamd09b0214878d
diff --git a/src/public/app/services/utils.js b/src/public/app/services/utils.js
index 0fa8e9642f..d2c11b0b3e 100644
--- a/src/public/app/services/utils.js
+++ b/src/public/app/services/utils.js
@@ -316,6 +316,24 @@ function dynamicRequire(moduleName) {
}
}
+function timeLimit(cb, limitMs) {
+ return new Promise((res, rej) => {
+ let resolved = false;
+
+ cb().then(() => {
+ resolved = true;
+
+ res();
+ });
+
+ setTimeout(() => {
+ if (!resolved) {
+ rej('Process exceeded time limit ' + limitMs);
+ }
+ }, limitMs);
+ });
+}
+
export default {
reloadApp,
parseDate,
@@ -355,5 +373,6 @@ export default {
normalizeShortcut,
copySelectionToClipboard,
isCKEditorInitialized,
- dynamicRequire
-};
\ No newline at end of file
+ dynamicRequire,
+ timeLimit
+};
diff --git a/src/public/app/services/ws.js b/src/public/app/services/ws.js
index 1c7fa78c17..a461d97221 100644
--- a/src/public/app/services/ws.js
+++ b/src/public/app/services/ws.js
@@ -157,7 +157,7 @@ async function consumeSyncData() {
const nonProcessedSyncRows = allSyncRows.filter(sync => !processedSyncIds.has(sync.id));
try {
- await processSyncRows(nonProcessedSyncRows);
+ await utils.timeLimit(async () => await processSyncRows(nonProcessedSyncRows), 5000);
}
catch (e) {
logError(`Encountered error ${e.message}: ${e.stack}, reloading frontend.`);