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
sync fixes
zadam5be7f003ca90
diff --git a/src/becca/entities/note.js b/src/becca/entities/note.jsindex da88a57126..37f158add1 100644--- a/src/becca/entities/note.js+++ b/src/becca/entities/note.js@@ -215,7 +215,8 @@ class Note extends AbstractEntity {entityId: this.noteId,hash: hash,isErased: false,- utcDateChanged: pojo.utcDateModified+ utcDateChanged: pojo.utcDateModified,+ isSynced: true}, null);}diff --git a/src/becca/entities/note_revision.js b/src/becca/entities/note_revision.jsindex b78c11aa21..bb9fd79e05 100644--- a/src/becca/entities/note_revision.js+++ b/src/becca/entities/note_revision.js@@ -131,7 +131,8 @@ class NoteRevision extends AbstractEntity {entityId: this.noteRevisionId,hash: hash,isErased: false,- utcDateChanged: this.getUtcDateChanged()+ utcDateChanged: this.getUtcDateChanged(),+ isSynced: true}, null);}diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex 96ee217c97..6cf549ae64 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -13,6 +13,7 @@ const dateUtils = require('./date_utils');const attributeService = require('./attributes');const noteRevisionService = require('./note_revisions');const becca = require("../becca/becca");+const utils = require("../services/utils");class ConsistencyChecks {constructor(autoFix) {@@ -291,13 +292,23 @@ class ConsistencyChecks {if (note.isProtected) {// this is wrong for non-erased notes but we cannot set a valid value for protected notes+ const utcDateModified = dateUtils.utcNowDateTime();+sql.upsert("note_contents", "noteId", {noteId: noteId,content: null,- utcDateModified: dateUtils.utcNowDateTime()+ utcDateModified: utcDateModified});- entityChangesService.addEntityChange('note_contents', noteId, "consistency_checks");+ const hash = utils.hash(noteId + "|null");++ entityChangesService.addEntityChange({+ entityName: 'note_contents',+ entityId: noteId,+ hash: hash,+ isErased: false,+ utcDateChanged: utcDateModified+ }, null);}else {// empty string might be wrong choice for some note types but it's a best guessdiff --git a/src/services/entity_changes.js b/src/services/entity_changes.jsindex d07fda1d5a..275a92640a 100644--- a/src/services/entity_changes.js+++ b/src/services/entity_changes.js@@ -25,8 +25,8 @@ function insertEntityChange(entityName, entityId, hash, isErased, utcDateChangedreturn entityChange;}-function addEntityChange(entityChange, sourceId, isSynced) {- const localEntityChange = insertEntityChange(entityChange.entityName, entityChange.entityId, entityChange.hash, entityChange.isErased, entityChange.utcDateChanged, sourceId, isSynced);+function addEntityChange(entityChange, sourceId) {+ const localEntityChange = insertEntityChange(entityChange.entityName, entityChange.entityId, entityChange.hash, entityChange.isErased, entityChange.utcDateChanged, sourceId, entityChange.isSynced);cls.addEntityChange(localEntityChange);}@@ -37,7 +37,8 @@ function addNoteReorderingEntityChange(parentNoteId, sourceId) {entityId: parentNoteId,hash: 'N/A',isErased: false,- utcDateChanged: dateUtils.utcNowDateTime()+ utcDateChanged: dateUtils.utcNowDateTime(),+ isSynced: true}, sourceId);const eventService = require('./events');@@ -104,7 +105,8 @@ function fillEntityChanges(entityName, entityPrimaryKey, condition = '') {entityId,hash: entity.generateHash(),isErased: false,- utcDateChanged: entity.getUtcDateChanged()+ utcDateChanged: entity.getUtcDateChanged(),+ isSynced: entityName !== 'options' || !!entity.isSynced}, null);}}diff --git a/src/services/sync.js b/src/services/sync.jsindex 1aed217757..0a919d18e3 100644--- a/src/services/sync.js+++ b/src/services/sync.js@@ -16,6 +16,7 @@ const request = require('./request');const ws = require('./ws');const entityChangesService = require('./entity_changes');const entityConstructor = require('../becca/entity_constructor');+const becca = require("../becca/becca");let proxyToggle = true;@@ -358,6 +359,9 @@ function getLastSyncedPull() {}function setLastSyncedPull(entityChangeId) {+ const lastSyncedPullOption = becca.getOption('lastSyncedPull');+ lastSyncedPullOption.value = entityChangeId + '';+// this way we avoid updating entity_changes which otherwise means that we've never pushed all entity_changessql.execute("UPDATE options SET value = ? WHERE name = ?", [entityChangeId, 'lastSyncedPull']);}@@ -373,6 +377,9 @@ function getLastSyncedPush() {function setLastSyncedPush(entityChangeId) {ws.setLastSyncedPush(entityChangeId);+ const lastSyncedPushOption = becca.getOption('lastSyncedPush');+ lastSyncedPushOption.value = entityChangeId + '';+// this way we avoid updating entity_changes which otherwise means that we've never pushed all entity_changessql.execute("UPDATE options SET value = ? WHERE name = ?", [entityChangeId, 'lastSyncedPush']);}