From 07c9c63d07b12e6a5d85797922d270bca214c885 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 13 Oct 2023 14:57:43 -0400 Subject: [PATCH] Avoids refresh on initial load while discovering --- src/git/gitProviderService.ts | 30 +++++++++++++++++------------- src/plus/webviews/focus/focusWebview.ts | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index 0eb207a..1cfcc4b 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -142,9 +142,11 @@ export class GitProviderService implements Disposable { get onDidChangeRepositories(): Event { return this._onDidChangeRepositories.event; } + private fireRepositoriesChanged(added?: Repository[], removed?: Repository[]) { - const openSchemes = this.openRepositories.map(r => r.uri.scheme); if (this.container.telemetry.enabled) { + const openSchemes = this.openRepositories.map(r => r.uri.scheme); + this.container.telemetry.setGlobalAttributes({ 'repositories.count': openSchemes.length, 'repositories.schemes': joinUnique(openSchemes, ','), @@ -163,7 +165,7 @@ export class GitProviderService implements Disposable { this._onDidChangeRepositories.fire({ added: added ?? [], removed: removed ?? [], etag: this._etag }); if (added?.length && this.container.telemetry.enabled) { - queueMicrotask(async () => { + setTimeout(async () => { for (const repo of added) { const remoteProviders = new Set(); @@ -181,7 +183,7 @@ export class GitProviderService implements Disposable { 'repository.remoteProviders': join(remoteProviders, ','), }); } - }); + }, 0); } } @@ -541,10 +543,12 @@ export class GitProviderService implements Disposable { >('git.autoRepositoryDetection'); if (this.container.telemetry.enabled) { - queueMicrotask(() => - this.container.telemetry.sendEvent('providers/registrationComplete', { - 'config.git.autoRepositoryDetection': autoRepositoryDetection, - }), + setTimeout( + () => + this.container.telemetry.sendEvent('providers/registrationComplete', { + 'config.git.autoRepositoryDetection': autoRepositoryDetection, + }), + 0, ); } @@ -576,8 +580,8 @@ export class GitProviderService implements Disposable { private _discoveredWorkspaceFolders = new Map>(); - private _isDiscoveringRepositories: Promise | undefined; - get isDiscoveringRepositories(): Promise | undefined { + private _isDiscoveringRepositories: Promise | undefined; + get isDiscoveringRepositories(): Promise | undefined { return this._isDiscoveringRepositories; } @@ -588,7 +592,7 @@ export class GitProviderService implements Disposable { this._isDiscoveringRepositories = undefined; } - const deferred = defer(); + const deferred = defer(); this._isDiscoveringRepositories = deferred.promise; try { @@ -630,7 +634,7 @@ export class GitProviderService implements Disposable { queueMicrotask(() => this.fireRepositoriesChanged(added)); } } finally { - deferred.fulfill(); + queueMicrotask(() => deferred.fulfill(this._etag)); } } @@ -910,7 +914,7 @@ export class GitProviderService implements Disposable { if (visibility == null) { visibility = await this.visibilityCore(repoPath); if (this.container.telemetry.enabled) { - queueMicrotask(() => { + setTimeout(() => { const repo = this.getRepository(repoPath); this.container.telemetry.sendEvent('repository/visibility', { 'repository.visibility': visibility, @@ -920,7 +924,7 @@ export class GitProviderService implements Disposable { 'repository.folder.scheme': repo?.folder?.uri.scheme, 'repository.provider.id': repo?.provider.id, }); - }); + }, 0); } } return visibility; diff --git a/src/plus/webviews/focus/focusWebview.ts b/src/plus/webviews/focus/focusWebview.ts index 4d9078d..8b0ac77 100644 --- a/src/plus/webviews/focus/focusWebview.ts +++ b/src/plus/webviews/focus/focusWebview.ts @@ -84,7 +84,9 @@ interface SearchedIssueWithRank extends SearchedIssue { export class FocusWebviewProvider implements WebviewProvider { private _pullRequests: SearchedPullRequestWithRemote[] = []; private _issues: SearchedIssueWithRank[] = []; + private _discovering: Promise | undefined; private readonly _disposable: Disposable; + private _etag?: number; private _etagSubscription?: number; private _repositoryEventsDisposable?: Disposable; private _repos?: RepoWithRichRemote[]; @@ -96,7 +98,16 @@ export class FocusWebviewProvider implements WebviewProvider { ) { this._disposable = Disposable.from( this.container.subscription.onDidChange(this.onSubscriptionChanged, this), - this.container.git.onDidChangeRepositories(() => void this.host.refresh(true)), + this.container.git.onDidChangeRepositories(async () => { + if (this._etag !== this.container.git.etag) { + if (this._discovering != null) { + this._etag = await this._discovering; + if (this._etag === this.container.git.etag) return; + } + + void this.host.refresh(true); + } + }), ); } @@ -424,6 +435,15 @@ export class FocusWebviewProvider implements WebviewProvider { private async getState(force?: boolean, deferState?: boolean): Promise { const webviewId = this.host.id; + this._etag = this.container.git.etag; + if (this.container.git.isDiscoveringRepositories) { + this._discovering = this.container.git.isDiscoveringRepositories.then(r => { + this._discovering = undefined; + return r; + }); + this._etag = await this._discovering; + } + const access = await this.getAccess(force); if (access.allowed !== true) { return {