Skip to content

Commit

Permalink
#91286 use throttled delayer for auto sync
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jan 20, 2022
1 parent 85dd6af commit 1043ddf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
12 changes: 5 additions & 7 deletions src/vs/platform/userDataSync/common/extensionsSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,11 @@ export class ExtensionsSynchroniser extends AbstractSynchroniser implements IUse
) {
super(SyncResource.Extensions, fileService, environmentService, storageService, userDataSyncStoreService, userDataSyncBackupStoreService, userDataSyncEnablementService, telemetryService, logService, configurationService, uriIdentityService);
this._register(
Event.debounce(
Event.any<any>(
Event.filter(this.extensionManagementService.onDidInstallExtensions, (e => e.some(({ local }) => !!local))),
Event.filter(this.extensionManagementService.onDidUninstallExtension, (e => !e.error)),
this.extensionEnablementService.onDidChangeEnablement,
this.extensionStorageService.onDidChangeExtensionStorageToSync),
() => undefined, 500)(() => this.triggerLocalChange()));
Event.any<any>(
Event.filter(this.extensionManagementService.onDidInstallExtensions, (e => e.some(({ local }) => !!local))),
Event.filter(this.extensionManagementService.onDidUninstallExtension, (e => !e.error)),
this.extensionEnablementService.onDidChangeEnablement,
this.extensionStorageService.onDidChangeExtensionStorageToSync)(() => this.triggerLocalChange()));
}

protected async generateSyncPreview(remoteUserData: IRemoteUserData, lastSyncUserData: ILastSyncUserData | null): Promise<IExtensionResourcePreview[]> {
Expand Down
10 changes: 5 additions & 5 deletions src/vs/platform/userDataSync/common/userDataAutoSyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { CancelablePromise, createCancelablePromise, Delayer, disposableTimeout, timeout } from 'vs/base/common/async';
import { CancelablePromise, createCancelablePromise, disposableTimeout, ThrottledDelayer, timeout } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
import { toLocalISOString } from 'vs/base/common/date';
import { toErrorMessage } from 'vs/base/common/errorMessage';
Expand Down Expand Up @@ -42,7 +42,7 @@ export class UserDataAutoSyncService extends Disposable implements IUserDataAuto
private readonly autoSync = this._register(new MutableDisposable<AutoSync>());
private successiveFailures: number = 0;
private lastSyncTriggerTime: number | undefined = undefined;
private readonly syncTriggerDelayer: Delayer<void>;
private readonly syncTriggerDelayer: ThrottledDelayer<void>;

private readonly _onError: Emitter<UserDataSyncError> = this._register(new Emitter<UserDataSyncError>());
readonly onError: Event<UserDataSyncError> = this._onError.event;
Expand Down Expand Up @@ -85,7 +85,7 @@ export class UserDataAutoSyncService extends Disposable implements IUserDataAuto
@IStorageService private readonly storageService: IStorageService,
) {
super();
this.syncTriggerDelayer = this._register(new Delayer<void>(0));
this.syncTriggerDelayer = this._register(new ThrottledDelayer<void>(this.getSyncTriggerDelayTime()));

this.lastSyncUrl = this.syncUrl;
this.syncUrl = userDataSyncStoreManagementService.userDataSyncStore?.url;
Expand Down Expand Up @@ -119,7 +119,7 @@ export class UserDataAutoSyncService extends Disposable implements IUserDataAuto

this._register(userDataSyncAccountService.onDidChangeAccount(() => this.updateAutoSync()));
this._register(userDataSyncStoreService.onDidChangeDonotMakeRequestsUntil(() => this.updateAutoSync()));
this._register(Event.debounce<string, string[]>(userDataSyncService.onDidChangeLocal, (last, source) => last ? [...last, source] : [source], 1000)(sources => this.triggerSync(sources, false, false)));
this._register(userDataSyncService.onDidChangeLocal(source => this.triggerSync([source], false, false)));
this._register(Event.filter(this.userDataSyncEnablementService.onDidChangeResourceEnablement, ([, enabled]) => enabled)(() => this.triggerSync(['resourceEnablement'], false, false)));
this._register(this.userDataSyncStoreManagementService.onDidChangeUserDataSyncStore(() => this.triggerSync(['userDataSyncStoreChanged'], false, false)));
}
Expand Down Expand Up @@ -351,7 +351,7 @@ export class UserDataAutoSyncService extends Disposable implements IUserDataAuto
}

protected getSyncTriggerDelayTime(): number {
return 1000; /* Debounce for a second if there are no failures */
return 2000; /* Debounce for 2 seconds if there are no failures */
}

}
Expand Down

0 comments on commit 1043ddf

Please sign in to comment.