mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01: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');
|
||||
|
||||
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
|
||||
};
|
@ -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 : 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) {}
|
||||
});
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user