Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix sync issues
zadam48abd765c6d2
diff --git a/db/migrations/0158__add_isSynced_to_sync.sql b/db/migrations/0158__add_isSynced_to_sync.sqlindex a2d978bc1d..2c419b9a05 100644--- a/db/migrations/0158__add_isSynced_to_sync.sql+++ b/db/migrations/0158__add_isSynced_to_sync.sql@@ -6,8 +6,8 @@ CREATE TABLE IF NOT EXISTS "sync_mig" (`isSynced` INTEGER default 0 not null,`utcSyncDate` TEXT NOT NULL);-INSERT INTO sync_mig (entityName, entityId, sourceId, isSynced, utcSyncDate)-SELECT entityName, entityId, sourceId, 1, utcSyncDate FROM sync;+INSERT INTO sync_mig (id, entityName, entityId, sourceId, isSynced, utcSyncDate)+SELECT id, entityName, entityId, sourceId, 1, utcSyncDate FROM sync;DROP TABLE sync;diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex 705ab02e65..d09aebb0b3 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -51,7 +51,7 @@ class ConsistencyChecks {childToParents[childNoteId].push(parentNoteId);}- function checkTreeCycle(noteId, path) {+ const checkTreeCycle = (noteId, path) => {if (noteId === 'root') {return;}@@ -75,7 +75,7 @@ class ConsistencyChecks {checkTreeCycle(parentNoteId, newPath);}}- }+ };const noteIds = Object.keys(childToParents);diff --git a/src/services/repository.js b/src/services/repository.jsindex 85cad2cd32..98effc1a61 100644--- a/src/services/repository.js+++ b/src/services/repository.js@@ -112,7 +112,7 @@ async function updateEntity(entity) {if (entity.isChanged) {const isSynced = entityName !== 'options' || entity.isSynced;- await syncTableService.addEntitySync(entityName, primaryKey, isSynced);+ await syncTableService.addEntitySync(entityName, primaryKey, null, isSynced);if (!cls.isEntityEventsDisabled()) {const eventPayload = {diff --git a/src/services/sync_table.js b/src/services/sync_table.jsindex 8134849a88..dec81fd191 100644--- a/src/services/sync_table.js+++ b/src/services/sync_table.js@@ -10,13 +10,13 @@ const cls = require('./cls');let maxSyncId = 0;-async function insertEntitySync(entityName, entityId, sourceId, isSynced) {+async function insertEntitySync(entityName, entityId, sourceId = null, isSynced = true) {const sync = {entityName: entityName,entityId: entityId,utcSyncDate: dateUtils.utcNowDateTime(),sourceId: sourceId || cls.getSourceId() || sourceIdService.getCurrentSourceId(),- isSynced: isSynced+ isSynced: isSynced ? 1 : 0};sync.id = await sql.replace("sync", sync);@@ -26,7 +26,7 @@ async function insertEntitySync(entityName, entityId, sourceId, isSynced) {return sync;}-async function addEntitySync(entityName, entityId, sourceId, isSynced = true) {+async function addEntitySync(entityName, entityId, sourceId, isSynced) {const sync = await insertEntitySync(entityName, entityId, sourceId, isSynced);cls.addSyncRow(sync);