未验证 提交 767b4ea7 编写于 作者: A Alex Dima

Add a cache for resolver results

上级 b6625830
......@@ -10,26 +10,32 @@ import { URI } from 'vs/base/common/uri';
export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverService {
declare readonly _serviceBrand: undefined;
private readonly _cache: Map<string, ResolverResult>;
constructor(
resourceUriProvider: ((uri: URI) => URI) | undefined
) {
this._cache = new Map<string, ResolverResult>();
if (resourceUriProvider) {
RemoteAuthorities.setDelegate(resourceUriProvider);
}
}
resolveAuthority(authority: string): Promise<ResolverResult> {
if (authority.indexOf(':') >= 0) {
const pieces = authority.split(':');
return Promise.resolve(this._createResolvedAuthority(authority, pieces[0], parseInt(pieces[1], 10)));
async resolveAuthority(authority: string): Promise<ResolverResult> {
if (!this._cache.has(authority)) {
const result = this._doResolveAuthority(authority);
RemoteAuthorities.set(authority, result.authority.host, result.authority.port);
this._cache.set(authority, result);
}
return Promise.resolve(this._createResolvedAuthority(authority, authority, 80));
return this._cache.get(authority)!;
}
private _createResolvedAuthority(authority: string, host: string, port: number): ResolverResult {
RemoteAuthorities.set(authority, host, port);
return { authority: { authority, host, port } };
private _doResolveAuthority(authority: string): ResolverResult {
if (authority.indexOf(':') >= 0) {
const pieces = authority.split(':');
return { authority: { authority, host: pieces[0], port: parseInt(pieces[1], 10) } };
}
return { authority: { authority, host: authority, port: 80 } };
}
clearResolvedAuthority(authority: string): void {
......
......@@ -30,7 +30,7 @@ export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverS
if (!this._resolveAuthorityRequests[authority]) {
let resolve: (value: ResolverResult) => void;
let reject: (err: any) => void;
let promise = new Promise<ResolverResult>((_resolve, _reject) => {
const promise = new Promise<ResolverResult>((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
});
......@@ -48,7 +48,7 @@ export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverS
setResolvedAuthority(resolvedAuthority: ResolvedAuthority, options?: ResolvedOptions) {
if (this._resolveAuthorityRequests[resolvedAuthority.authority]) {
let request = this._resolveAuthorityRequests[resolvedAuthority.authority];
const request = this._resolveAuthorityRequests[resolvedAuthority.authority];
RemoteAuthorities.set(resolvedAuthority.authority, resolvedAuthority.host, resolvedAuthority.port);
request.resolve({ authority: resolvedAuthority, options });
}
......@@ -56,7 +56,7 @@ export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverS
setResolvedAuthorityError(authority: string, err: any): void {
if (this._resolveAuthorityRequests[authority]) {
let request = this._resolveAuthorityRequests[authority];
const request = this._resolveAuthorityRequests[authority];
request.reject(err);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册