Skip to content

Build your personal knowledge base with Trilium Notes

Merge remote-tracking branch 'origin/stable'

zadamf4a4e746bf68
diff --cc src/routes/api/login.js
index 42abafdd81,8027c11edb..5bb8e33277
--- a/src/routes/api/login.js
+++ b/src/routes/api/login.js
@@@ -49,7 -49,7 +49,7 @@@ function loginSync(req)
return {
sourceId: sourceIdService.getCurrentSourceId(),
- maxSyncId: sql.getValue("SELECT MAX(id) FROM sync WHERE isSynced = 1")
- maxSyncId: await sql.getValue("SELECT COALESCE(MAX(id), 0) FROM sync WHERE isSynced = 1")
++ maxSyncId: sql.getValue("SELECT COALESCE(MAX(id), 0) FROM sync WHERE isSynced = 1")
};
}
diff --cc src/routes/api/sync.js
index 7a1d3c58b3,8f85480172..05a476b941
--- a/src/routes/api/sync.js
+++ b/src/routes/api/sync.js
@@@ -47,10 -47,10 +47,10 @@@ function getStats()
};
}
-async function checkSync() {
+function checkSync() {
return {
- entityHashes: await contentHashService.getEntityHashes(),
- maxSyncId: await sql.getValue('SELECT COALESCE(MAX(id), 0) FROM sync WHERE isSynced = 1')
+ entityHashes: contentHashService.getEntityHashes(),
- maxSyncId: sql.getValue('SELECT MAX(id) FROM sync WHERE isSynced = 1')
++ maxSyncId: sql.getValue('SELECT COALESCE(MAX(id), 0) FROM sync WHERE isSynced = 1')
};
}
@@@ -120,11 -120,11 +120,11 @@@ function getChanged(req)
const lastSyncId = parseInt(req.query.lastSyncId);
- const syncs = await sql.getRows("SELECT * FROM sync WHERE isSynced = 1 AND id > ? LIMIT 1000", [lastSyncId]);
+ const syncs = sql.getRows("SELECT * FROM sync WHERE isSynced = 1 AND id > ? LIMIT 1000", [lastSyncId]);
const ret = {
- syncs: await syncService.getSyncRecords(syncs),
- maxSyncId: await sql.getValue('SELECT COALESCE(MAX(id), 0) FROM sync WHERE isSynced = 1')
+ syncs: syncService.getSyncRecords(syncs),
- maxSyncId: sql.getValue('SELECT MAX(id) FROM sync WHERE isSynced = 1')
++ maxSyncId: sql.getValue('SELECT COALESCE(MAX(id), 0) FROM sync WHERE isSynced = 1')
};
if (ret.syncs.length > 0) {
diff --cc src/routes/index.js
index 34d942425c,28bd0e290e..9cc366d83e
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@@ -22,10 -22,10 +22,10 @@@ function index(req, res)
mainFontSize: parseInt(options.mainFontSize),
treeFontSize: parseInt(options.treeFontSize),
detailFontSize: parseInt(options.detailFontSize),
- sourceId: await sourceIdService.generateSourceId(),
- maxSyncIdAtLoad: await sql.getValue("SELECT COALESCE(MAX(id), 0) FROM sync"),
+ sourceId: sourceIdService.generateSourceId(),
- maxSyncIdAtLoad: sql.getValue("SELECT MAX(id) FROM sync"),
++ maxSyncIdAtLoad: sql.getValue("SELECT COALESCE(MAX(id), 0) FROM sync"),
instanceName: config.General ? config.General.instanceName : null,
- appCssNoteIds: await getAppCssNoteIds(),
+ appCssNoteIds: getAppCssNoteIds(),
isDev: env.isDev(),
isMainWindow: !req.query.extra
});
diff --cc src/services/app_info.js
index 930d170f07,af90d2b89f..1434fb1ce4
--- a/src/services/app_info.js
+++ b/src/services/app_info.js
@@@ -4,7 -4,7 +4,7 @@@ const build = require('./build')
const packageJson = require('../../package');
const {TRILIUM_DATA_DIR} = require('./data_dir');
- const APP_DB_VERSION = 161;
-const APP_DB_VERSION = 159;
++const APP_DB_VERSION = 162;
const SYNC_VERSION = 14;
const CLIPPER_PROTOCOL_VERSION = "1.0";
diff --cc src/services/sync.js
index a34c778eb3,13eae7426f..d43e7bb9c8
--- a/src/services/sync.js
+++ b/src/services/sync.js
@@@ -123,10 -123,10 +123,10 @@@ async function doLogin()
}
async function pullSync(syncContext) {
- let appliedPulls = 0;
+ let atLeastOnePullApplied = false;
while (true) {
- const lastSyncedPull = await getLastSyncedPull();
+ const lastSyncedPull = getLastSyncedPull();
const changesUri = '/api/sync/changed?lastSyncId=' + lastSyncedPull;
const startDate = Date.now();
@@@ -147,28 -147,28 +147,28 @@@
break;
}
- await sql.transactional(async () => {
+ sql.transactional(() => {
for (const {sync, entity} of rows) {
if (!sourceIdService.isLocalSourceId(sync.sourceId)) {
- if (appliedPulls === 0 && sync.entity !== 'recent_notes') { // send only for first
+ if (!atLeastOnePullApplied && sync.entity !== 'recent_notes') { // send only for first
ws.syncPullInProgress();
- appliedPulls++;
+ atLeastOnePullApplied = true;
}
- await syncUpdateService.updateEntity(sync, entity, syncContext.sourceId);
+ syncUpdateService.updateEntity(sync, entity, syncContext.sourceId);
}
stats.outstandingPulls = resp.maxSyncId - sync.id;
}
- await setLastSyncedPull(rows[rows.length - 1].sync.id);
+ setLastSyncedPull(rows[rows.length - 1].sync.id);
});
- log.info(`Pulled ${rows.length} changes in ${pulledDate - startDate}ms from ${changesUri} and applied them in ${Date.now() - pulledDate}ms`);
+ log.info(`Pulled ${rows.length} changes starting at syncId=${lastSyncedPull} in ${pulledDate - startDate}ms and applied them in ${Date.now() - pulledDate}ms, ${stats.outstandingPulls} outstanding pulls`);
}
- if (appliedPulls > 0) {
+ if (atLeastOnePullApplied) {
ws.syncPullFinished();
}
@@@ -367,11 -367,11 +367,11 @@@ function updatePushStats()
}
}
-async function getMaxSyncId() {
- return await sql.getValue('SELECT COALESCE(MAX(id), 0) FROM sync');
+function getMaxSyncId() {
- return sql.getValue('SELECT MAX(id) FROM sync');
++ return sql.getValue('SELECT COALESCE(MAX(id), 0) FROM sync');
}
-sqlInit.dbReady.then(async () => {
+sqlInit.dbReady.then(() => {
setInterval(cls.wrap(sync), 60000);
// kickoff initial sync immediately