Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[_] feat/debounce remote manager sync #493

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading