Skip to content

Build your personal knowledge base with Trilium Notes

last_synced is now updated after sync is completed

azivnerf6033705a765
diff --git a/routes/api/sync.js b/routes/api/sync.js
index 391cc4dada..b73b44aedf 100644
--- a/routes/api/sync.js
+++ b/routes/api/sync.js
@@ -4,11 +4,13 @@ const express = require('express');
const router = express.Router();
const sql = require('../../services/sql');
const auth = require('../../services/auth');
+const utils = require('../../services/utils');
router.get('/changed/:since', auth.checkApiAuth, async (req, res, next) => {
const since = parseInt(req.params.since);
res.send({
+ 'syncTimestamp': utils.nowTimestamp(),
'tree': await sql.getResults("select * from notes_tree where date_modified >= ?", [since]),
'notes': await sql.getFlattenedResults('note_id', "select note_id from notes where date_modified >= ?", [since]),
'audit_log': await sql.getResults("select * from audit_log where date_modified >= ?", [since])
diff --git a/services/sync.js b/services/sync.js
index 12b3cde732..5f6af12d2c 100644
--- a/services/sync.js
+++ b/services/sync.js
@@ -29,7 +29,7 @@ async function sync() {
});
try {
- sql.beginTransaction();
+ await sql.beginTransaction();
for (const treeItem of resp.tree) {
delete treeItem['id'];
@@ -73,10 +73,12 @@ async function sync() {
}
}
- sql.commit();
+ await sql.setOption('last_synced', syncTimestamp);
+
+ await sql.commit();
}
catch (e) {
- sql.rollback();
+ await sql.rollback();
throw e;
}