Bladeren bron

Avoids multiple web requests for visibility

main
Eric Amodio 1 jaar geleden
bovenliggende
commit
acf0cfd906
1 gewijzigde bestanden met toevoegingen van 10 en 1 verwijderingen
  1. +10
    -1
      src/env/node/git/localGitProvider.ts

+ 10
- 1
src/env/node/git/localGitProvider.ts Bestand weergeven

@ -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];
}

Laden…
Annuleren
Opslaan