Skip to content

Commit

Permalink
Merge pull request #493 from internxt/feat/debounce-remote-manager-sync
Browse files Browse the repository at this point in the history
[_] feat/debounce remote manager sync
  • Loading branch information
miguelsw authored Apr 30, 2024
2 parents 877053f + ac33aa4 commit 5a7f46d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/apps/main/remote-sync/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { ipcMain } from 'electron';
import { reportError } from '../bug-report/service';
import { sleep } from '../util';
import { broadcastToWindows } from '../windows';
import {
updateSyncEngine,
fallbackSyncEngine,
} from '../background-processes/sync-engine';
import { updateSyncEngine,fallbackSyncEngine} from '../background-processes/sync-engine';
import { debounce } from 'lodash';

const SYNC_DEBOUNCE_DELAY = 3_000;

let initialSyncReady = false;
const driveFilesCollection = new DriveFilesCollection();
Expand Down Expand Up @@ -85,7 +85,7 @@ export async function updateRemoteSync(): Promise<void> {
// that we received the notification, but if we check
// for new data we don't receive it
await sleep(2_000);
await remoteSyncManager.startRemoteSync();
await startRemoteSync();
updateSyncEngine();
}
export async function fallbackRemoteSync(): Promise<void> {
Expand All @@ -99,8 +99,15 @@ ipcMain.handle('SYNC_MANUALLY', async () => {
await fallbackRemoteSync();
});

eventBus.on('RECEIVED_REMOTE_CHANGES', async () => {
const debouncedSynchronization = debounce(async () => {
await updateRemoteSync();
}, SYNC_DEBOUNCE_DELAY);

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
debouncedSynchronization();
});

eventBus.on('USER_LOGGED_IN', async () => {
Expand Down

0 comments on commit 5a7f46d

Please sign in to comment.