From 767b4ea7f98c7720498503753f9ba2467a74271d Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 11 Jun 2020 09:08:03 +0200 Subject: [PATCH] Add a cache for resolver results --- .../browser/remoteAuthorityResolverService.ts | 22 ++++++++++++------- .../remoteAuthorityResolverService.ts | 6 ++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts b/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts index 4daa3d9b654..a363734f833 100644 --- a/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts +++ b/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts @@ -10,26 +10,32 @@ import { URI } from 'vs/base/common/uri'; export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverService { declare readonly _serviceBrand: undefined; + private readonly _cache: Map; constructor( resourceUriProvider: ((uri: URI) => URI) | undefined ) { + this._cache = new Map(); if (resourceUriProvider) { RemoteAuthorities.setDelegate(resourceUriProvider); } } - resolveAuthority(authority: string): Promise { - 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 { + 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 { diff --git a/src/vs/platform/remote/electron-browser/remoteAuthorityResolverService.ts b/src/vs/platform/remote/electron-browser/remoteAuthorityResolverService.ts index 639711ba2a2..d42a91b21c6 100644 --- a/src/vs/platform/remote/electron-browser/remoteAuthorityResolverService.ts +++ b/src/vs/platform/remote/electron-browser/remoteAuthorityResolverService.ts @@ -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((_resolve, _reject) => { + const promise = new Promise((_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); } } -- GitLab