fix sync status

This commit is contained in:
zadam 2021-05-15 22:00:53 +02:00
parent 623200b92b
commit f6dd1110e8
4 changed files with 19 additions and 12 deletions

View File

@ -126,27 +126,29 @@ export default class SyncStatusWidget extends BasicWidget {
}); });
this.syncState = 'in-progress'; this.syncState = 'in-progress';
this.allChangesPushed = false; this.lastSyncedPush = message.lastSyncedPush;
} }
else if (message.type === 'sync-push-in-progress') { else if (message.type === 'sync-push-in-progress') {
this.syncState = 'in-progress'; this.syncState = 'in-progress';
this.allChangesPushed = false; this.lastSyncedPush = message.lastSyncedPush;
} }
else if (message.type === 'sync-finished') { else if (message.type === 'sync-finished') {
// this gives user a chance to see the toast in case of fast sync finish // this gives user a chance to see the toast in case of fast sync finish
setTimeout(() => toastService.closePersistent('sync'), 1000); setTimeout(() => toastService.closePersistent('sync'), 1000);
this.syncState = 'connected'; this.syncState = 'connected';
this.lastSyncedPush = message.lastSyncedPush;
} }
else if (message.type === 'sync-failed') { else if (message.type === 'sync-failed') {
this.syncState = 'disconnected'; this.syncState = 'disconnected';
this.lastSyncedPush = message.lastSyncedPush;
} }
else if (message.type === 'frontend-update') { else if (message.type === 'frontend-update') {
const {lastSyncedPush} = message.data; this.lastSyncedPush = message.data.lastSyncedPush;
this.allChangesPushed = lastSyncedPush === ws.getMaxKnownEntityChangeSyncId();
} }
this.allChangesPushed = this.lastSyncedPush === ws.getMaxKnownEntityChangeSyncId();
if (['unknown', 'in-progress'].includes(this.syncState)) { if (['unknown', 'in-progress'].includes(this.syncState)) {
this.showIcon(this.syncState); this.showIcon(this.syncState);
} else { } else {

View File

@ -50,7 +50,9 @@ function addNoteReorderingEntityChange(parentNoteId, sourceId) {
function moveEntityChangeToTop(entityName, entityId) { function moveEntityChangeToTop(entityName, entityId) {
const ec = sql.getRow(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [entityName, entityId]); const ec = sql.getRow(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [entityName, entityId]);
insertEntityChange(entityName, entityId, ec.hash, ec.isErased, ec.utcDateChanged, ec.sourceId, ec.isSynced); const localEntityChange = insertEntityChange(entityName, entityId, ec.hash, ec.isErased, ec.utcDateChanged, ec.sourceId, ec.isSynced);
cls.addEntityChange(localEntityChange);
} }
function addEntityChangesForSector(entityName, sector) { function addEntityChangesForSector(entityName, sector) {

View File

@ -334,6 +334,7 @@ function getEntityChangesRecords(entityChanges) {
const entity = getEntityChangeRow(entityChange.entityName, entityChange.entityId); const entity = getEntityChangeRow(entityChange.entityName, entityChange.entityId);
if (entityChange.entityName === 'options' && !entity.isSynced) { if (entityChange.entityName === 'options' && !entity.isSynced) {
// if non-synced entities should count towards "lastSyncedPush"
records.push({entityChange}); records.push({entityChange});
continue; continue;
@ -358,7 +359,8 @@ function getLastSyncedPull() {
} }
function setLastSyncedPull(entityChangeId) { function setLastSyncedPull(entityChangeId) {
optionService.setOption('lastSyncedPull', 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']);
} }
function getLastSyncedPush() { function getLastSyncedPush() {
@ -372,7 +374,8 @@ function getLastSyncedPush() {
function setLastSyncedPush(entityChangeId) { function setLastSyncedPush(entityChangeId) {
ws.setLastSyncedPush(entityChangeId); ws.setLastSyncedPush(entityChangeId);
optionService.setOption('lastSyncedPush', 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']);
} }
function getMaxEntityChangeId() { function getMaxEntityChangeId() {

View File

@ -127,19 +127,19 @@ function sendTransactionEntityChangesToAllClients() {
} }
function syncPullInProgress() { function syncPullInProgress() {
sendMessageToAllClients({ type: 'sync-pull-in-progress' }); sendMessageToAllClients({ type: 'sync-pull-in-progress', lastSyncedPush });
} }
function syncPushInProgress() { function syncPushInProgress() {
sendMessageToAllClients({ type: 'sync-push-in-progress' }); sendMessageToAllClients({ type: 'sync-push-in-progress', lastSyncedPush });
} }
function syncFinished() { function syncFinished() {
sendMessageToAllClients({ type: 'sync-finished' }); sendMessageToAllClients({ type: 'sync-finished', lastSyncedPush });
} }
function syncFailed() { function syncFailed() {
sendMessageToAllClients({ type: 'sync-failed' }); sendMessageToAllClients({ type: 'sync-failed', lastSyncedPush });
} }
function setLastSyncedPush(entityChangeId) { function setLastSyncedPush(entityChangeId) {