fix: only update on session change when needed

This commit is contained in:
Dallin Romney 2025-07-31 10:21:59 -07:00
parent 4101b30d7e
commit 6ba01825b4
2 changed files with 37 additions and 10 deletions

View file

@ -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

View file

@ -36,9 +36,7 @@ export const TRIAL_PROXY_URL =
export class ControlPlaneClient {
constructor(
private readonly sessionInfoPromise: Promise<
ControlPlaneSessionInfo | undefined
>,
readonly sessionInfoPromise: Promise<ControlPlaneSessionInfo | undefined>,
private readonly ideSettingsPromise: Promise<IdeSettings>,
private readonly ideInfoPromise: Promise<IdeInfo>,
) {}