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
fixed sync
azivnercd90200272e1
diff --git a/services/messaging.js b/services/messaging.jsindex 90079af7b7..70fe674e4a 100644--- a/services/messaging.js+++ b/services/messaging.js@@ -1,4 +1,3 @@-const utils = require('../services/utils');const WebSocket = require('ws');let webSocketServer;@@ -10,7 +9,7 @@ function init(httpServer) {});}-async function send(message) {+async function sendMessage(message) {const jsonStr = JSON.stringify(message);webSocketServer.clients.forEach(function each(client) {@@ -22,5 +21,5 @@ async function send(message) {module.exports = {init,- send+ sendMessage};\ No newline at end of filediff --git a/services/ping_job.js b/services/ping_job.jsindex 74d059fef8..80fc036b74 100644--- a/services/ping_job.js+++ b/services/ping_job.js@@ -32,7 +32,7 @@ setInterval(async () => {const changesToPushCount = await sql.getSingleValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]);- messaging.send({+ messaging.sendMessage({type: 'sync',data: data,changesToPushCount: sync.isSyncSetup ? changesToPushCount : 0diff --git a/services/source_id.js b/services/source_id.jsindex 59efbd20a9..f5ba89d775 100644--- a/services/source_id.js+++ b/services/source_id.js@@ -17,7 +17,7 @@ sql.dbReady.then(async () => {});});- allSourceIds = await sql.getFlattenedResults("source_id", "SELECT source_id FROM source_ids");+ allSourceIds = await sql.getFlattenedResults("source_id", "SELECT source_id FROM source_ids ORDER BY date_created DESC");}catch (e) {}});diff --git a/services/sql.js b/services/sql.jsindex 1631482617..cc48d3e85d 100644--- a/services/sql.js+++ b/services/sql.js@@ -122,38 +122,43 @@ async function wrap(func) {}}+let transactionActive = false;let transactionPromise = null;async function doInTransaction(func) {- while (transactionPromise !== null) {+ while (transactionActive) {await transactionPromise;}const error = new Error(); // to capture correct stack trace in case of exception+ transactionActive = true;transactionPromise = new Promise(async (resolve, reject) => {try {-await beginTransaction();await func();await commit();+ transactionActive = false;resolve();- transactionPromise = null;}catch (e) {log.error("Error executing transaction, executing rollback. Inner exception: " + e.stack + error.stack);await rollback();+ transactionActive = false;resolve();- transactionPromise = null;throw e;}});++ if (transactionActive) {+ await transactionPromise;+ }}dbReady