From f6033705a7655f7bdb238fc8893db8d940d6d855 Mon Sep 17 00:00:00 2001 From: azivner Date: Thu, 26 Oct 2017 19:22:21 -0400 Subject: [PATCH] last_synced is now updated after sync is completed --- routes/api/sync.js | 2 ++ services/sync.js | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/routes/api/sync.js b/routes/api/sync.js index 391cc4dad..b73b44aed 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 12b3cde73..5f6af12d2 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; }