From 6ba01825b40b2c3715f683edbe4f56376dcd84ce Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 31 Jul 2025 10:21:59 -0700 Subject: [PATCH] fix: only update on session change when needed --- core/config/ConfigHandler.ts | 43 ++++++++++++++++++++++++++++++------ core/control-plane/client.ts | 4 +--- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index f936196fa..b50fb638d 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -363,13 +363,42 @@ export class ConfigHandler { async updateControlPlaneSessionInfo( sessionInfo: ControlPlaneSessionInfo | undefined, ) { - this.controlPlaneClient = new ControlPlaneClient( - Promise.resolve(sessionInfo), - this.ideSettingsPromise, - this.ide.getIdeInfo(), - ); - this.abortCascade(); - await this.cascadeInit("Control plane session info update"); + const currentSession = await this.controlPlaneClient.sessionInfoPromise; + const newSession = sessionInfo; + + let reload = false; + if (newSession) { + if (currentSession) { + if ( + newSession.AUTH_TYPE !== AuthType.OnPrem && + currentSession.AUTH_TYPE !== AuthType.OnPrem + ) { + if (newSession.account.id !== currentSession.account.id) { + // session id change (non-on-prem) + reload = true; + } + } + } else { + // log in + reload = true; + } + } else { + if (currentSession) { + // log out + reload = true; + } + } + + if (reload) { + this.controlPlaneClient = new ControlPlaneClient( + Promise.resolve(sessionInfo), + this.ideSettingsPromise, + this.ide.getIdeInfo(), + ); + this.abortCascade(); + await this.cascadeInit("Control plane session info update"); + } + return reload; } // Org id: check id validity, save selection, switch and reload diff --git a/core/control-plane/client.ts b/core/control-plane/client.ts index 58b2ed71b..ad6112aa9 100644 --- a/core/control-plane/client.ts +++ b/core/control-plane/client.ts @@ -36,9 +36,7 @@ export const TRIAL_PROXY_URL = export class ControlPlaneClient { constructor( - private readonly sessionInfoPromise: Promise< - ControlPlaneSessionInfo | undefined - >, + readonly sessionInfoPromise: Promise, private readonly ideSettingsPromise: Promise, private readonly ideInfoPromise: Promise, ) {}