sync fixes

This commit is contained in:
zadam 2021-06-29 23:45:45 +02:00
parent b660238a40
commit 5be7f003ca
5 changed files with 30 additions and 8 deletions

View File

@ -215,7 +215,8 @@ class Note extends AbstractEntity {
entityId: this.noteId,
hash: hash,
isErased: false,
utcDateChanged: pojo.utcDateModified
utcDateChanged: pojo.utcDateModified,
isSynced: true
}, null);
}

View File

@ -131,7 +131,8 @@ class NoteRevision extends AbstractEntity {
entityId: this.noteRevisionId,
hash: hash,
isErased: false,
utcDateChanged: this.getUtcDateChanged()
utcDateChanged: this.getUtcDateChanged(),
isSynced: true
}, null);
}

View File

@ -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 guess

View File

@ -25,8 +25,8 @@ function insertEntityChange(entityName, entityId, hash, isErased, utcDateChanged
return 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);
}
}

View File

@ -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_changes
sql.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_changes
sql.execute("UPDATE options SET value = ? WHERE name = ?", [entityChangeId, 'lastSyncedPush']);
}