mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fixed sync
This commit is contained in:
parent
91c2f9e7cb
commit
cd90200272
@ -1,4 +1,3 @@
|
|||||||
const utils = require('../services/utils');
|
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
|
|
||||||
let webSocketServer;
|
let webSocketServer;
|
||||||
@ -10,7 +9,7 @@ function init(httpServer) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function send(message) {
|
async function sendMessage(message) {
|
||||||
const jsonStr = JSON.stringify(message);
|
const jsonStr = JSON.stringify(message);
|
||||||
|
|
||||||
webSocketServer.clients.forEach(function each(client) {
|
webSocketServer.clients.forEach(function each(client) {
|
||||||
@ -22,5 +21,5 @@ async function send(message) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init,
|
init,
|
||||||
send
|
sendMessage
|
||||||
};
|
};
|
@ -32,7 +32,7 @@ setInterval(async () => {
|
|||||||
|
|
||||||
const changesToPushCount = await sql.getSingleValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]);
|
const changesToPushCount = await sql.getSingleValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]);
|
||||||
|
|
||||||
messaging.send({
|
messaging.sendMessage({
|
||||||
type: 'sync',
|
type: 'sync',
|
||||||
data: data,
|
data: data,
|
||||||
changesToPushCount: sync.isSyncSetup ? changesToPushCount : 0
|
changesToPushCount: sync.isSyncSetup ? changesToPushCount : 0
|
||||||
|
@ -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) {}
|
catch (e) {}
|
||||||
});
|
});
|
||||||
|
@ -122,38 +122,43 @@ async function wrap(func) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let transactionActive = false;
|
||||||
let transactionPromise = null;
|
let transactionPromise = null;
|
||||||
|
|
||||||
async function doInTransaction(func) {
|
async function doInTransaction(func) {
|
||||||
while (transactionPromise !== null) {
|
while (transactionActive) {
|
||||||
await transactionPromise;
|
await transactionPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
const error = new Error(); // to capture correct stack trace in case of exception
|
const error = new Error(); // to capture correct stack trace in case of exception
|
||||||
|
|
||||||
|
transactionActive = true;
|
||||||
transactionPromise = new Promise(async (resolve, reject) => {
|
transactionPromise = new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
await beginTransaction();
|
await beginTransaction();
|
||||||
|
|
||||||
await func();
|
await func();
|
||||||
|
|
||||||
await commit();
|
await commit();
|
||||||
|
|
||||||
|
transactionActive = false;
|
||||||
resolve();
|
resolve();
|
||||||
transactionPromise = null;
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
log.error("Error executing transaction, executing rollback. Inner exception: " + e.stack + error.stack);
|
log.error("Error executing transaction, executing rollback. Inner exception: " + e.stack + error.stack);
|
||||||
|
|
||||||
await rollback();
|
await rollback();
|
||||||
|
|
||||||
|
transactionActive = false;
|
||||||
resolve();
|
resolve();
|
||||||
transactionPromise = null;
|
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (transactionActive) {
|
||||||
|
await transactionPromise;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dbReady
|
dbReady
|
||||||
|
Loading…
x
Reference in New Issue
Block a user