mirror of
https://github.com/zadam/trilium.git
synced 2025-01-17 20:48:12 +08:00
sync fixes
This commit is contained in:
parent
aff9ce97ee
commit
eb4dfbad92
2 changed files with 17 additions and 9 deletions
|
@ -67,7 +67,7 @@ async function prepareNode(branch) {
|
||||||
const note = await branch.getNote();
|
const note = await branch.getNote();
|
||||||
|
|
||||||
if (!note) {
|
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;
|
const title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title;
|
||||||
|
|
|
@ -59,6 +59,10 @@ async function handleMessage(event) {
|
||||||
|
|
||||||
syncDataQueue.push(...syncRows);
|
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 finish
|
// first wait for all the preceding consumers to finish
|
||||||
while (consumeQueuePromise) {
|
while (consumeQueuePromise) {
|
||||||
await consumeQueuePromise;
|
await consumeQueuePromise;
|
||||||
|
@ -132,15 +136,19 @@ async function consumeSyncData() {
|
||||||
|
|
||||||
const outsideSyncData = allSyncData.filter(sync => sync.sourceId !== glob.sourceId);
|
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
|
try {
|
||||||
lastAcceptedSyncId = Math.max(lastAcceptedSyncId, allSyncData[allSyncData.length - 1].id);
|
|
||||||
sendPing();
|
|
||||||
|
|
||||||
// the update process should be synchronous as a whole but individual handlers can run in parallel
|
// the update process should be synchronous as a whole but individual handlers can run in parallel
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
...allSyncMessageHandlers.map(syncHandler => runSafely(syncHandler, allSyncData)),
|
...allSyncMessageHandlers.map(syncHandler => runSafely(syncHandler, allSyncData)),
|
||||||
...outsideSyncMessageHandlers.map(syncHandler => runSafely(syncHandler, outsideSyncData))
|
...outsideSyncMessageHandlers.map(syncHandler => runSafely(syncHandler, outsideSyncData))
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
logError(`Encountered error ${e.message}, reloading frontend.`);
|
||||||
|
|
||||||
|
// 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);
|
lastProcessedSyncId = Math.max(lastProcessedSyncId, allSyncData[allSyncData.length - 1].id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue