From c6d912dcb7c5288cee3a03e0e07d7c5ba00b5c78 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 9 Mar 2020 21:34:03 +0100 Subject: [PATCH] sync only changes with isSynced = true --- .../a2c75661-f9e2-478f-a69f-6a9409e69997.xml | 44 +++++++++++++++++-- src/routes/api/login.js | 2 +- src/routes/api/sync.js | 6 +-- src/services/sync.js | 6 +-- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml index ede612a71..99eaaea72 100644 --- a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml +++ b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml @@ -57,6 +57,7 @@ 1 apiTokenId + 1 @@ -130,17 +131,21 @@ 1 attributeId + 1 noteId + name value + value + attributeId @@ -207,14 +212,17 @@ value 1 branchId + 1 noteId parentNoteId + parentNoteId + branchId @@ -245,6 +253,7 @@ parentNoteId 1 noteId + 1 @@ -275,6 +284,7 @@ parentNoteId 1 noteRevisionId + 1 @@ -359,22 +369,28 @@ parentNoteId 1 noteRevisionId + 1 noteId + utcDateLastEdited + utcDateCreated + dateLastEdited + dateCreated + noteRevisionId @@ -461,28 +477,36 @@ parentNoteId 1 noteId + 1 title + type + isDeleted + dateCreated + dateModified + utcDateCreated + utcDateModified + noteId @@ -523,6 +547,7 @@ parentNoteId 1 name + 1 @@ -558,6 +583,7 @@ parentNoteId 1 noteId + 1 @@ -578,10 +604,12 @@ parentNoteId 1 sourceId + 1 utcDateCreated + sourceId @@ -635,20 +663,28 @@ parentNoteId TEXT|0s 1 - + 5 + INTEGER|0s + 1 + 0 + + + 6 TEXT|0s 1 - + entityName entityId + 1 - + utcSyncDate + - + id 1 diff --git a/src/routes/api/login.js b/src/routes/api/login.js index e3ed0c5e5..23d78807a 100644 --- a/src/routes/api/login.js +++ b/src/routes/api/login.js @@ -49,7 +49,7 @@ async function loginSync(req) { return { sourceId: sourceIdService.getCurrentSourceId(), - maxSyncId: await sql.getValue("SELECT MAX(id) FROM sync") + maxSyncId: await sql.getValue("SELECT MAX(id) FROM sync WHERE isSynced = 1") }; } diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index 08fc9cfa5..ddd2b4148 100644 --- a/src/routes/api/sync.js +++ b/src/routes/api/sync.js @@ -50,7 +50,7 @@ async function getStats() { async function checkSync() { return { entityHashes: await contentHashService.getEntityHashes(), - maxSyncId: await sql.getValue('SELECT MAX(id) FROM sync') + maxSyncId: await sql.getValue('SELECT MAX(id) FROM sync WHERE isSynced = 1') }; } @@ -116,11 +116,11 @@ async function forceNoteSync(req) { async function getChanged(req) { const lastSyncId = parseInt(req.query.lastSyncId); - const syncs = await sql.getRows("SELECT * FROM sync WHERE id > ? LIMIT 1000", [lastSyncId]); + const syncs = await sql.getRows("SELECT * FROM sync WHERE isSynced = 1 AND id > ? LIMIT 1000", [lastSyncId]); return { syncs: await syncService.getSyncRecords(syncs), - maxSyncId: await sql.getValue('SELECT MAX(id) FROM sync') + maxSyncId: await sql.getValue('SELECT MAX(id) FROM sync WHERE isSynced = 1') }; } diff --git a/src/services/sync.js b/src/services/sync.js index 0d965d88f..583f052bc 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -176,7 +176,7 @@ async function pushSync(syncContext) { let lastSyncedPush = await getLastSyncedPush(); while (true) { - const syncs = await sql.getRows('SELECT * FROM sync WHERE id > ? LIMIT 1000', [lastSyncedPush]); + const syncs = await sql.getRows('SELECT * FROM sync WHERE isSynced = 1 AND id > ? LIMIT 1000', [lastSyncedPush]); if (syncs.length === 0) { log.info("Nothing to push"); @@ -236,7 +236,7 @@ async function checkContentHash(syncContext) { return true; } - const notPushedSyncs = await sql.getValue("SELECT EXISTS(SELECT 1 FROM sync WHERE id > ?)", [await getLastSyncedPush()]); + const notPushedSyncs = await sql.getValue("SELECT EXISTS(SELECT 1 FROM sync WHERE isSynced = 1 AND id > ?)", [await getLastSyncedPush()]); if (notPushedSyncs) { log.info(`There's ${notPushedSyncs} outstanding pushes, skipping content check.`); @@ -353,7 +353,7 @@ async function updatePushStats() { if (await syncOptions.isSyncSetup()) { const lastSyncedPush = await optionService.getOption('lastSyncedPush'); - stats.outstandingPushes = await sql.getValue("SELECT COUNT(1) FROM sync WHERE id > ?", [lastSyncedPush]); + stats.outstandingPushes = await sql.getValue("SELECT COUNT(1) FROM sync WHERE isSynced = 1 AND id > ?", [lastSyncedPush]); } }