Skip to content

Commit

Permalink
debounce remote manager sync
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanVicens committed Apr 15, 2024
1 parent 279de18 commit 5bfb632
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/apps/main/remote-sync/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 5bfb632

Please sign in to comment.