added document_id for sync identification

This commit is contained in:
azivner
2017-10-28 13:19:12 -04:00
parent c5f80051ae
commit 724f4b43b7
6 changed files with 32 additions and 4 deletions

View File

@@ -112,6 +112,7 @@ async function sync() {
async function getChangedSince(since) {
return {
'documentId': await getDocumentId(),
'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]),
@@ -167,6 +168,22 @@ async function putNote(note) {
log.info("Update/sync note " + note.detail.note_id);
}
let documentIdCache = null;
async function getDocumentId() {
if (!documentIdCache) {
documentIdCache = await sql.getOption('document_id');
if (!documentIdCache) {
documentIdCache = utils.randomString(16);
await sql.setOption('document_id', documentIdCache);
}
}
return documentIdCache;
}
if (SYNC_SERVER) {
log.info("Setting up sync");