From acf0cfd9060602ea47b81e8201d9aee1c4638f0e Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 11 Jul 2023 11:20:10 -0400 Subject: [PATCH] Avoids multiple web requests for visibility --- src/env/node/git/localGitProvider.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 76fa6ef..43d5877 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -571,6 +571,7 @@ export class LocalGitProvider implements GitProvider, Disposable { : [RepositoryVisibility.Private, getVisibilityCacheKey(remotes)]; } + private _pendingRemoteVisibility = new Map>(); @debug({ args: { 0: r => r.url }, exit: r => `returned ${r[0]}` }) private async getRemoteVisibility( remote: GitRemote, @@ -589,14 +590,22 @@ export class LocalGitProvider implements GitProvider, Disposable { if (url == null) return [RepositoryVisibility.Private, remote]; // Check if the url returns a 200 status code + let promise = this._pendingRemoteVisibility.get(url); + if (promise == null) { + promise = fetch(url, { method: 'HEAD', agent: getProxyAgent() }); + this._pendingRemoteVisibility.set(url, promise); + } + try { - const rsp = await fetch(url, { method: 'HEAD', agent: getProxyAgent() }); + const rsp = await promise; if (rsp.ok) return [RepositoryVisibility.Public, remote]; Logger.debug(scope, `Response=${rsp.status}`); } catch (ex) { debugger; Logger.error(ex, scope); + } finally { + this._pendingRemoteVisibility.delete(url); } return [RepositoryVisibility.Private, remote]; }