Skip to content

Commit 07c9c63

Browse files
committed
Avoids refresh on initial load while discovering
1 parent 5999a26 commit 07c9c63

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

src/git/gitProviderService.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ export class GitProviderService implements Disposable {
142142
get onDidChangeRepositories(): Event<RepositoriesChangeEvent> {
143143
return this._onDidChangeRepositories.event;
144144
}
145+
145146
private fireRepositoriesChanged(added?: Repository[], removed?: Repository[]) {
146-
const openSchemes = this.openRepositories.map(r => r.uri.scheme);
147147
if (this.container.telemetry.enabled) {
148+
const openSchemes = this.openRepositories.map(r => r.uri.scheme);
149+
148150
this.container.telemetry.setGlobalAttributes({
149151
'repositories.count': openSchemes.length,
150152
'repositories.schemes': joinUnique(openSchemes, ','),
@@ -163,7 +165,7 @@ export class GitProviderService implements Disposable {
163165
this._onDidChangeRepositories.fire({ added: added ?? [], removed: removed ?? [], etag: this._etag });
164166

165167
if (added?.length && this.container.telemetry.enabled) {
166-
queueMicrotask(async () => {
168+
setTimeout(async () => {
167169
for (const repo of added) {
168170
const remoteProviders = new Set<string>();
169171

@@ -181,7 +183,7 @@ export class GitProviderService implements Disposable {
181183
'repository.remoteProviders': join(remoteProviders, ','),
182184
});
183185
}
184-
});
186+
}, 0);
185187
}
186188
}
187189

@@ -541,10 +543,12 @@ export class GitProviderService implements Disposable {
541543
>('git.autoRepositoryDetection');
542544

543545
if (this.container.telemetry.enabled) {
544-
queueMicrotask(() =>
545-
this.container.telemetry.sendEvent('providers/registrationComplete', {
546-
'config.git.autoRepositoryDetection': autoRepositoryDetection,
547-
}),
546+
setTimeout(
547+
() =>
548+
this.container.telemetry.sendEvent('providers/registrationComplete', {
549+
'config.git.autoRepositoryDetection': autoRepositoryDetection,
550+
}),
551+
0,
548552
);
549553
}
550554

@@ -576,8 +580,8 @@ export class GitProviderService implements Disposable {
576580

577581
private _discoveredWorkspaceFolders = new Map<WorkspaceFolder, Promise<Repository[]>>();
578582

579-
private _isDiscoveringRepositories: Promise<void> | undefined;
580-
get isDiscoveringRepositories(): Promise<void> | undefined {
583+
private _isDiscoveringRepositories: Promise<number> | undefined;
584+
get isDiscoveringRepositories(): Promise<number> | undefined {
581585
return this._isDiscoveringRepositories;
582586
}
583587

@@ -588,7 +592,7 @@ export class GitProviderService implements Disposable {
588592
this._isDiscoveringRepositories = undefined;
589593
}
590594

591-
const deferred = defer<void>();
595+
const deferred = defer<number>();
592596
this._isDiscoveringRepositories = deferred.promise;
593597

594598
try {
@@ -630,7 +634,7 @@ export class GitProviderService implements Disposable {
630634
queueMicrotask(() => this.fireRepositoriesChanged(added));
631635
}
632636
} finally {
633-
deferred.fulfill();
637+
queueMicrotask(() => deferred.fulfill(this._etag));
634638
}
635639
}
636640

@@ -910,7 +914,7 @@ export class GitProviderService implements Disposable {
910914
if (visibility == null) {
911915
visibility = await this.visibilityCore(repoPath);
912916
if (this.container.telemetry.enabled) {
913-
queueMicrotask(() => {
917+
setTimeout(() => {
914918
const repo = this.getRepository(repoPath);
915919
this.container.telemetry.sendEvent('repository/visibility', {
916920
'repository.visibility': visibility,
@@ -920,7 +924,7 @@ export class GitProviderService implements Disposable {
920924
'repository.folder.scheme': repo?.folder?.uri.scheme,
921925
'repository.provider.id': repo?.provider.id,
922926
});
923-
});
927+
}, 0);
924928
}
925929
}
926930
return visibility;

src/plus/webviews/focus/focusWebview.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ interface SearchedIssueWithRank extends SearchedIssue {
8484
export class FocusWebviewProvider implements WebviewProvider<State> {
8585
private _pullRequests: SearchedPullRequestWithRemote[] = [];
8686
private _issues: SearchedIssueWithRank[] = [];
87+
private _discovering: Promise<number | undefined> | undefined;
8788
private readonly _disposable: Disposable;
89+
private _etag?: number;
8890
private _etagSubscription?: number;
8991
private _repositoryEventsDisposable?: Disposable;
9092
private _repos?: RepoWithRichRemote[];
@@ -96,7 +98,16 @@ export class FocusWebviewProvider implements WebviewProvider<State> {
9698
) {
9799
this._disposable = Disposable.from(
98100
this.container.subscription.onDidChange(this.onSubscriptionChanged, this),
99-
this.container.git.onDidChangeRepositories(() => void this.host.refresh(true)),
101+
this.container.git.onDidChangeRepositories(async () => {
102+
if (this._etag !== this.container.git.etag) {
103+
if (this._discovering != null) {
104+
this._etag = await this._discovering;
105+
if (this._etag === this.container.git.etag) return;
106+
}
107+
108+
void this.host.refresh(true);
109+
}
110+
}),
100111
);
101112
}
102113

@@ -424,6 +435,15 @@ export class FocusWebviewProvider implements WebviewProvider<State> {
424435
private async getState(force?: boolean, deferState?: boolean): Promise<State> {
425436
const webviewId = this.host.id;
426437

438+
this._etag = this.container.git.etag;
439+
if (this.container.git.isDiscoveringRepositories) {
440+
this._discovering = this.container.git.isDiscoveringRepositories.then(r => {
441+
this._discovering = undefined;
442+
return r;
443+
});
444+
this._etag = await this._discovering;
445+
}
446+
427447
const access = await this.getAccess(force);
428448
if (access.allowed !== true) {
429449
return {

0 commit comments

Comments
 (0)