Pārlūkot izejas kodu

Avoids multiple web requests for visibility

main
Eric Amodio pirms 1 gada
vecāks
revīzija
acf0cfd906
1 mainītis faili ar 10 papildinājumiem un 1 dzēšanām
  1. +10
    -1
      src/env/node/git/localGitProvider.ts

+ 10
- 1
src/env/node/git/localGitProvider.ts Parādīt failu

@ -571,6 +571,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
: [RepositoryVisibility.Private, getVisibilityCacheKey(remotes)];
}
private _pendingRemoteVisibility = new Map<string, ReturnType<typeof fetch>>();
@debug<LocalGitProvider['getRemoteVisibility']>({ 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];
}

Notiek ielāde…
Atcelt
Saglabāt