From a7dc453c405a6621e44f4792955e98334c26a818 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Thu, 23 Nov 2023 12:27:11 +0200 Subject: [PATCH 1/6] Fix incorrect redirection update sags behaviour on reconnection --- src/state/sync/saga.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/state/sync/saga.js b/src/state/sync/saga.js index b5de8406d..1b5340bf6 100644 --- a/src/state/sync/saga.js +++ b/src/state/sync/saga.js @@ -215,15 +215,8 @@ function* requestsRedirectUpdate({ payload }) { if (result) { yield put(actions.setSyncMode(types.MODE_ONLINE)) - const syncProgress = yield select(getSyncProgress) - const isSyncing = Number.isInteger(syncProgress) && syncProgress !== 100 - if (isSyncing) { - yield put(actions.setIsSyncing(true)) - } else { - yield put(actions.setIsSyncing(false)) - yield put(actions.setIsSyncRequired(false)) - yield put(updateStatus({ id: 'sync.sync-done' })) - } + yield put(actions.setIsSyncing(false)) + yield put(actions.setIsSyncRequired(false)) } else { yield put(actions.setSyncMode(types.MODE_OFFLINE)) yield put(actions.forceQueryFromDb()) From 8d8fa1f82f61fc67ec189cb36d3c2871252bafc0 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Thu, 23 Nov 2023 12:34:32 +0200 Subject: [PATCH 2/6] Fix redundant sync reqs chaining in some corner cases --- src/components/ErrorDialog/ErrorDialog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ErrorDialog/ErrorDialog.js b/src/components/ErrorDialog/ErrorDialog.js index 00289aaeb..af1ca2c57 100644 --- a/src/components/ErrorDialog/ErrorDialog.js +++ b/src/components/ErrorDialog/ErrorDialog.js @@ -29,7 +29,7 @@ const ErrorDialog = ({ useEffect(() => { if (shouldStartSync) startSync() - }, [shouldStartSync]) + }, []) const handleClose = () => { toggleDialog(false) From d7c02dff54b2176e1b5834a33051a0eaa2794103 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Thu, 23 Nov 2023 12:39:51 +0200 Subject: [PATCH 3/6] Add sync_finished ws event const --- src/state/sync/constants.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/state/sync/constants.js b/src/state/sync/constants.js index b9d8e607d..33515574a 100644 --- a/src/state/sync/constants.js +++ b/src/state/sync/constants.js @@ -27,4 +27,5 @@ export default { WS_REQUESTS_REDIRECT: 'ws_emitRedirectingRequestsStatusToApi', SYNC_INTERRUPTED: 'SYNCHRONIZATION_HAS_BEEN_INTERRUPTED', SYNC_NOT_STARTED: 'SYNCHRONIZATION_HAS_NOT_STARTED_YET', + SYNC_FINISHED: 'SYNCHRONIZATION_IS_FINISHED', } From b0d2f60497fec18b41cecc5ee948613883a7097b Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Thu, 23 Nov 2023 12:48:51 +0200 Subject: [PATCH 4/6] Improve synchronization state checking --- src/state/sync/saga.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/state/sync/saga.js b/src/state/sync/saga.js index 1b5340bf6..f44c4cffd 100644 --- a/src/state/sync/saga.js +++ b/src/state/sync/saga.js @@ -201,6 +201,8 @@ function* progressUpdate({ payload }) { if (!isSyncInProgress || state === types.SYNC_INTERRUPTED) { yield put(actions.setIsSyncing(false)) if (error) yield put(updateSyncErrorStatus(error)) + } else if (state === types.SYNC_FINISHED) { + yield put(actions.setIsSyncing(false)) } else { const syncProgress = Number.isInteger(progress) ? progress From 74c01a90734d865cf28b5bed9c8e8656cedabeed Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Thu, 23 Nov 2023 13:17:37 +0200 Subject: [PATCH 5/6] Improve redirection update saga flow --- src/state/sync/saga.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/state/sync/saga.js b/src/state/sync/saga.js index f44c4cffd..7734d81d2 100644 --- a/src/state/sync/saga.js +++ b/src/state/sync/saga.js @@ -218,7 +218,6 @@ function* requestsRedirectUpdate({ payload }) { if (result) { yield put(actions.setSyncMode(types.MODE_ONLINE)) yield put(actions.setIsSyncing(false)) - yield put(actions.setIsSyncRequired(false)) } else { yield put(actions.setSyncMode(types.MODE_OFFLINE)) yield put(actions.forceQueryFromDb()) From afa9457c00dd927a66eedf5cfd6b3447301973b4 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 28 Nov 2023 11:48:12 +0200 Subject: [PATCH 6/6] Improve syncing req checking on stop sync --- src/state/sync/saga.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/state/sync/saga.js b/src/state/sync/saga.js index 7734d81d2..0b2e9a6ab 100644 --- a/src/state/sync/saga.js +++ b/src/state/sync/saga.js @@ -76,9 +76,10 @@ function* startSyncNow() { function* stopSyncNow() { const { result, error } = yield call(syncNowStop) if (result) { + const { result: haveSyncedAtLeastOnce } = yield call(haveCollsBeenSyncedAtLeastOnce) + yield put(actions.setIsSyncRequired(!haveSyncedAtLeastOnce)) yield put(actions.setIsSyncing(false)) yield put(actions.setEstimatedTime({})) - yield put(actions.setIsSyncRequired(true)) yield put(updateStatus({ id: 'sync.logout' })) } if (error) {