diff --git a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml index 5557cbb99..99eaaea72 100644 --- a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml +++ b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml @@ -10,5 +10,683 @@ + +
+
+
+
+
+
+
+
+
+
+ 1 +
+ + 1 +
+ + + 1 + TEXT|0s + 1 + + + 2 + TEXT|0s + 1 + + + 3 + TEXT|0s + 1 + + + 4 + INT|0s + 1 + 0 + + + 5 + TEXT|0s + 1 + "" + + + 1 + apiTokenId + + 1 + + + apiTokenId + 1 + sqlite_autoindex_api_tokens_1 + + + 1 + TEXT|0s + 1 + + + 2 + TEXT|0s + 1 + + + 3 + TEXT|0s + 1 + + + 4 + TEXT|0s + 1 + + + 5 + TEXT|0s + 1 + '' + + + 6 + INT|0s + 1 + 0 + + + 7 + TEXT|0s + 1 + + + 8 + TEXT|0s + 1 + + + 9 + INT|0s + 1 + + + 10 + TEXT|0s + NULL + + + 11 + TEXT|0s + 1 + "" + + + 12 + int|0s + 0 + + + 1 + attributeId + + 1 + + + noteId + + + + name +value + + + + value + + + + attributeId + 1 + sqlite_autoindex_attributes_1 + + + 1 + TEXT|0s + 1 + + + 2 + TEXT|0s + 1 + + + 3 + TEXT|0s + 1 + + + 4 + INTEGER|0s + 1 + + + 5 + TEXT|0s + + + 6 + INTEGER|0s + 1 + 0 + + + 7 + INTEGER|0s + 1 + 0 + + + 8 + TEXT|0s + NULL + + + 9 + TEXT|0s + 1 + + + 10 + TEXT|0s + 1 + + + 11 + TEXT|0s + 1 + "" + + + 1 + branchId + + 1 + + + noteId +parentNoteId + + + + parentNoteId + + + + branchId + 1 + sqlite_autoindex_branches_1 + + + 1 + TEXT|0s + 1 + + + 2 + TEXT|0s + NULL + + + 3 + TEXT|0s + 1 + "" + + + 4 + TEXT|0s + 1 + + + 1 + noteId + + 1 + + + noteId + 1 + sqlite_autoindex_note_contents_1 + + + 1 + TEXT|0s + 1 + + + 2 + TEXT|0s + + + 3 + TEXT|0s + 1 + '' + + + 4 + TEXT|0s + 1 + + + 1 + noteRevisionId + + 1 + + + noteRevisionId + 1 + sqlite_autoindex_note_revision_contents_1 + + + 1 + TEXT|0s + 1 + + + 2 + TEXT|0s + 1 + + + 3 + TEXT|0s + + + 4 + INT|0s + 1 + + + 5 + INT|0s + 1 + 0 + + + 6 + INT|0s + 1 + 0 + + + 7 + TEXT|0s + 1 + + + 8 + TEXT|0s + 1 + + + 9 + TEXT|0s + 1 + + + 10 + TEXT|0s + 1 + + + 11 + TEXT|0s + 1 + + + 12 + TEXT|0s + 1 + '' + + + 13 + TEXT|0s + 1 + '' + + + 14 + TEXT|0s + 1 + '' + + + 1 + noteRevisionId + + 1 + + + noteId + + + + utcDateLastEdited + + + + utcDateCreated + + + + dateLastEdited + + + + dateCreated + + + + noteRevisionId + 1 + sqlite_autoindex_note_revisions_1 + + + 1 + TEXT|0s + 1 + + + 2 + TEXT|0s + 1 + "note" + + + 3 + INT|0s + 1 + + + 4 + INT|0s + 1 + 0 + + + 5 + TEXT|0s + 1 + 'text' + + + 6 + TEXT|0s + 1 + 'text/html' + + + 7 + TEXT|0s + 1 + "" + + + 8 + INT|0s + 1 + 0 + + + 9 + TEXT|0s + NULL + + + 10 + INT|0s + 1 + 0 + + + 11 + TEXT|0s + 1 + + + 12 + TEXT|0s + 1 + + + 13 + TEXT|0s + 1 + + + 14 + TEXT|0s + 1 + + + 1 + noteId + + 1 + + + title + + + + type + + + + isDeleted + + + + dateCreated + + + + dateModified + + + + utcDateCreated + + + + utcDateModified + + + + noteId + 1 + sqlite_autoindex_notes_1 + + + 1 + TEXT|0s + 1 + + + 2 + TEXT|0s + + + 3 + INTEGER|0s + 1 + 0 + + + 4 + TEXT|0s + 1 + "" + + + 5 + TEXT|0s + 1 + + + 6 + TEXT|0s + 1 + + + 1 + name + + 1 + + + name + 1 + sqlite_autoindex_options_1 + + + 1 + TEXT|0s + 1 + + + 2 + TEXT|0s + 1 + + + 3 + TEXT|0s + 1 + "" + + + 4 + TEXT|0s + 1 + + + 5 + INT|0s + + + 1 + noteId + + 1 + + + noteId + 1 + sqlite_autoindex_recent_notes_1 + + + 1 + TEXT|0s + 1 + + + 2 + TEXT|0s + 1 + + + 1 + sourceId + + 1 + + + utcDateCreated + + + + sourceId + 1 + sqlite_autoindex_source_ids_1 + + + 1 + text|0s + + + 2 + text|0s + + + 3 + text|0s + + + 4 + int|0s + + + 5 + text|0s + + + 1 + + + 2 + + + 1 + INTEGER|0s + 1 + 1 + + + 2 + TEXT|0s + 1 + + + 3 + TEXT|0s + 1 + + + 4 + TEXT|0s + 1 + + + 5 + INTEGER|0s + 1 + 0 + + + 6 + TEXT|0s + 1 + + + entityName +entityId + + 1 + + + utcSyncDate + + + + id + 1 + \ No newline at end of file diff --git a/src/services/repository.js b/src/services/repository.js index c36cb7782..85cad2cd3 100644 --- a/src/services/repository.js +++ b/src/services/repository.js @@ -110,7 +110,9 @@ async function updateEntity(entity) { const primaryKey = entity[primaryKeyName]; if (entity.isChanged) { - await syncTableService.addEntitySync(entityName, primaryKey); + const isSynced = entityName !== 'options' || entity.isSynced; + + await syncTableService.addEntitySync(entityName, primaryKey, isSynced); if (!cls.isEntityEventsDisabled()) { const eventPayload = { diff --git a/src/services/sync_table.js b/src/services/sync_table.js index dcae6e64d..f552085cc 100644 --- a/src/services/sync_table.js +++ b/src/services/sync_table.js @@ -1,16 +1,20 @@ +/** + * TODO: rename "sync" table to something like "changelog" since it now also contains rows which are not synced (isSynced=false) + */ + const sql = require('./sql'); const sourceIdService = require('./source_id'); const dateUtils = require('./date_utils'); const log = require('./log'); const cls = require('./cls'); -async function insertEntitySync(entityName, entityId, sourceId) { +async function insertEntitySync(entityName, entityId, sourceId, isSynced) { const sync = { entityName: entityName, entityId: entityId, utcSyncDate: dateUtils.utcNowDateTime(), sourceId: sourceId || cls.getSourceId() || sourceIdService.getCurrentSourceId(), - isSynced: 1 + isSynced: isSynced }; sync.id = await sql.replace("sync", sync); @@ -18,8 +22,8 @@ async function insertEntitySync(entityName, entityId, sourceId) { return sync; } -async function addEntitySync(entityName, entityId, sourceId) { - const sync = await insertEntitySync(entityName, entityId, sourceId); +async function addEntitySync(entityName, entityId, sourceId, isSynced = true) { + const sync = await insertEntitySync(entityName, entityId, sourceId, isSynced); cls.addSyncRow(sync); } @@ -28,7 +32,15 @@ async function addEntitySyncsForSector(entityName, entityPrimaryKey, sector) { const entityIds = await sql.getColumn(`SELECT ${entityPrimaryKey} FROM ${entityName} WHERE SUBSTR(${entityPrimaryKey}, 1, 1) = ?`, [sector]); for (const entityId of entityIds) { - await insertEntitySync(entityName, entityId, 'content-check'); + if (entityName === 'options') { + const isSynced = await sql.getValue(`SELECT isSynced FROM options WHERE name = ?`, [entityId]); + + if (!isSynced) { + continue; + } + } + + await insertEntitySync(entityName, entityId, 'content-check', true); } } @@ -97,7 +109,7 @@ module.exports = { addNoteReorderingSync: async (parentNoteId, sourceId) => await addEntitySync("note_reordering", parentNoteId, sourceId), addNoteRevisionSync: async (noteRevisionId, sourceId) => await addEntitySync("note_revisions", noteRevisionId, sourceId), addNoteRevisionContentSync: async (noteRevisionId, sourceId) => await addEntitySync("note_revision_contents", noteRevisionId, sourceId), - addOptionsSync: async (name, sourceId) => await addEntitySync("options", name, sourceId), + addOptionsSync: async (name, sourceId, isSynced) => await addEntitySync("options", name, sourceId, isSynced), addRecentNoteSync: async (noteId, sourceId) => await addEntitySync("recent_notes", noteId, sourceId), addAttributeSync: async (attributeId, sourceId) => await addEntitySync("attributes", attributeId, sourceId), addApiTokenSync: async (apiTokenId, sourceId) => await addEntitySync("api_tokens", apiTokenId, sourceId), diff --git a/src/services/sync_update.js b/src/services/sync_update.js index 10b8a5112..59de06337 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -176,7 +176,7 @@ async function updateOptions(remoteEntity, sourceId) { if (shouldWeUpdateEntity(localEntity, remoteEntity)) { await sql.replace('options', remoteEntity); - await syncTableService.addOptionsSync(remoteEntity.name, sourceId); + await syncTableService.addOptionsSync(remoteEntity.name, sourceId, true); } }); }