From 56a321f7cd4b8aeb07e9081762fe027b6c004e06 Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Mon, 15 Jun 2020 13:28:19 +0300 Subject: [PATCH] use map for cache Signed-off-by: Jari Kolehmainen --- src/main/shell-session.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/shell-session.ts b/src/main/shell-session.ts index 7efa43b8bf..90e87737fb 100644 --- a/src/main/shell-session.ts +++ b/src/main/shell-session.ts @@ -11,6 +11,7 @@ import { helmCli } from "./helm-cli" export class ShellSession extends EventEmitter { static shellEnv: any + static shellEnvs: Map = new Map() protected websocket: WebSocket protected shellProcess: pty.IPty @@ -21,6 +22,7 @@ export class ShellSession extends EventEmitter { protected helmBinDir: string; protected preferences: ClusterPreferences; protected running = false; + protected clusterId: string; constructor(socket: WebSocket, pathToKubeconfig: string, cluster: Cluster) { super() @@ -28,6 +30,7 @@ export class ShellSession extends EventEmitter { this.kubeconfigPath = pathToKubeconfig this.kubectl = new Kubectl(cluster.version) this.preferences = cluster.preferences || {} + this.clusterId = cluster.id } public async open() { @@ -80,15 +83,14 @@ export class ShellSession extends EventEmitter { protected async getCachedShellEnv() { let env: any - if (!ShellSession.shellEnv) { + env = ShellSession.shellEnvs.get(this.clusterId) + if (!env) { env = await this.getShellEnv() - ShellSession.shellEnv = env + ShellSession.shellEnvs.set(this.clusterId, env) } else { - env = ShellSession.shellEnv - // refresh env in the background this.getShellEnv().then((shellEnv: any) => { - ShellSession.shellEnv = shellEnv + ShellSession.shellEnvs.set(this.clusterId, shellEnv) }) }