From afadd6ec06a8460d108d0f8522c941fdc9712f23 Mon Sep 17 00:00:00 2001 From: azivner Date: Sun, 29 Oct 2017 16:14:59 -0400 Subject: [PATCH] added date_modified to options as preparation for options syncing --- migrations/0019__date_modified_for_options.sql | 1 + public/javascripts/sync.js | 4 +++- public/javascripts/tree.js | 6 ++++-- services/migration.js | 2 +- services/sql.js | 4 +++- services/sync.js | 12 ++++++------ 6 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 migrations/0019__date_modified_for_options.sql diff --git a/migrations/0019__date_modified_for_options.sql b/migrations/0019__date_modified_for_options.sql new file mode 100644 index 000000000..47684ba97 --- /dev/null +++ b/migrations/0019__date_modified_for_options.sql @@ -0,0 +1 @@ +ALTER TABLE options ADD COLUMN date_modified INTEGER NOT NULL DEFAULT 0 \ No newline at end of file diff --git a/public/javascripts/sync.js b/public/javascripts/sync.js index 8a7f5387c..38515a614 100644 --- a/public/javascripts/sync.js +++ b/public/javascripts/sync.js @@ -4,7 +4,9 @@ function syncNow() { type: 'POST', success: result => { if (result.success) { - alert("Sync finished successfully"); + checkAudit(); + + message("Sync finished successfully"); for (const l of result.log) { diff --git a/public/javascripts/tree.js b/public/javascripts/tree.js index a5d1e6906..cf04b3abd 100644 --- a/public/javascripts/tree.js +++ b/public/javascripts/tree.js @@ -88,7 +88,7 @@ let globalEncryptionSessionTimeout; let globalEncryptedDataKey; let globalFullLoadTime; -setInterval(() => { +function checkAudit() { $.ajax({ url: baseApiUrl + 'audit/' + globalFullLoadTime, type: 'GET', @@ -109,7 +109,9 @@ setInterval(() => { } } }); -}, 10 * 1000); +} + +setInterval(checkAudit, 10 * 1000); $(() => { $.get(baseApiUrl + 'tree').then(resp => { diff --git a/services/migration.js b/services/migration.js index 437d0c119..935019ea4 100644 --- a/services/migration.js +++ b/services/migration.js @@ -3,7 +3,7 @@ const sql = require('./sql'); const fs = require('fs-extra'); const log = require('./log'); -const APP_DB_VERSION = 18; +const APP_DB_VERSION = 19; const MIGRATIONS_DIR = "./migrations"; async function migrate() { diff --git a/services/sql.js b/services/sql.js index 97cc92875..1c0df1a3b 100644 --- a/services/sql.js +++ b/services/sql.js @@ -44,7 +44,9 @@ async function getOption(optName) { } async function setOption(optName, optValue) { - await execute("UPDATE options SET opt_value = ? WHERE opt_name = ?", [optValue, optName]); + const now = utils.nowTimestamp(); + + await execute("UPDATE options SET opt_value = ?, date_modified = ? WHERE opt_name = ?", [optValue, now, optName]); } async function getSingleResult(query, params = []) { diff --git a/services/sync.js b/services/sync.js index 3687666ea..f0893ecfd 100644 --- a/services/sync.js +++ b/services/sync.js @@ -158,11 +158,11 @@ async function login() { async function sync() { const syncLog = []; - // if (syncInProgress) { - // syncLog.push("Sync already in progress"); - // - // return syncLog; - // } + if (syncInProgress) { + syncLog.push("Sync already in progress"); + + return syncLog; + } syncInProgress = true; @@ -269,7 +269,7 @@ async function putNote(note, syncLog) { } } -if (SYNC_SERVER && false) { +if (SYNC_SERVER) { log.info("Setting up sync"); setInterval(sync, 60000);