From 5bfb63287bb85d1f2035efdb6bfbd924e6a9d357 Mon Sep 17 00:00:00 2001 From: joan vicens Date: Mon, 15 Apr 2024 14:46:18 +0200 Subject: [PATCH 1/2] debounce remote manager sync --- src/apps/main/remote-sync/handlers.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/apps/main/remote-sync/handlers.ts b/src/apps/main/remote-sync/handlers.ts index d79e8a915..991f5cc84 100644 --- a/src/apps/main/remote-sync/handlers.ts +++ b/src/apps/main/remote-sync/handlers.ts @@ -10,6 +10,7 @@ import { reportError } from '../bug-report/service'; import { sleep } from '../util'; import { broadcastToWindows } from '../windows'; import { updateSyncEngine } from '../background-processes/sync-engine'; +import { debounce } from 'lodash'; let initialSyncReady = false; const driveFilesCollection = new DriveFilesCollection(); @@ -77,14 +78,16 @@ ipcMain.handle('get-remote-sync-status', () => remoteSyncManager.getSyncStatus() ); +const debouncedSynchronization = debounce(async () => { + await startRemoteSync(); + updateSyncEngine(); +}, 3_000); + eventBus.on('RECEIVED_REMOTE_CHANGES', async () => { // Wait before checking for updates, could be possible // that we received the notification, but if we check // for new data we don't receive it - await sleep(2_000); - - await remoteSyncManager.startRemoteSync(); - updateSyncEngine(); + debouncedSynchronization(); }); eventBus.on('USER_LOGGED_IN', async () => { From 85898c548c4ead856a9d1a4c0bdde1e353af36b2 Mon Sep 17 00:00:00 2001 From: joan vicens Date: Mon, 15 Apr 2024 15:18:21 +0200 Subject: [PATCH 2/2] chore: give name to magic number --- src/apps/main/remote-sync/handlers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/apps/main/remote-sync/handlers.ts b/src/apps/main/remote-sync/handlers.ts index 991f5cc84..7054dc87f 100644 --- a/src/apps/main/remote-sync/handlers.ts +++ b/src/apps/main/remote-sync/handlers.ts @@ -12,6 +12,8 @@ import { broadcastToWindows } from '../windows'; import { updateSyncEngine } from '../background-processes/sync-engine'; import { debounce } from 'lodash'; +const SYNC_DEBOUNCE_DELAY = 3_000; + let initialSyncReady = false; const driveFilesCollection = new DriveFilesCollection(); const driveFoldersCollection = new DriveFoldersCollection(); @@ -81,7 +83,7 @@ ipcMain.handle('get-remote-sync-status', () => const debouncedSynchronization = debounce(async () => { await startRemoteSync(); updateSyncEngine(); -}, 3_000); +}, SYNC_DEBOUNCE_DELAY); eventBus.on('RECEIVED_REMOTE_CHANGES', async () => { // Wait before checking for updates, could be possible