From 464a15102e19f3a226bd6468a1c170eaf709f888 Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 15 Feb 2025 13:45:10 -0800 Subject: [PATCH] refactor reloadHubAssistants --- core/config/ConfigHandler.ts | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index d85839f8f..a61f62354 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -229,6 +229,22 @@ export class ConfigHandler { return false; } + private async reloadHubAssistants() { + const newFullSlugsList = + await this.controlPlaneClient.listAssistantFullSlugs(this.selectedOrgId); + + if (newFullSlugsList) { + const shouldReload = this.fullSlugsListsDiffer( + newFullSlugsList, + this.lastFullSlugsList, + ); + if (shouldReload) { + await this.loadPlatformProfiles(); + } + this.lastFullSlugsList = newFullSlugsList; + } + } + private async fetchControlPlaneProfiles() { if (await useHub(this.ideSettingsPromise)) { clearInterval(this.platformProfilesRefreshInterval); @@ -236,23 +252,10 @@ export class ConfigHandler { // Every 5 seconds we ask the platform whether there are any assistant updates in the last 5 seconds // If so, we do the full (more expensive) reload - this.platformProfilesRefreshInterval = setInterval(async () => { - const newFullSlugsList = - await this.controlPlaneClient.listAssistantFullSlugs( - this.selectedOrgId, - ); - - if (newFullSlugsList) { - const shouldReload = this.fullSlugsListsDiffer( - newFullSlugsList, - this.lastFullSlugsList, - ); - if (shouldReload) { - await this.loadPlatformProfiles(); - } - this.lastFullSlugsList = newFullSlugsList; - } - }, PlatformProfileLoader.RELOAD_INTERVAL); + this.platformProfilesRefreshInterval = setInterval( + this.reloadHubAssistants.bind(this), + PlatformProfileLoader.RELOAD_INTERVAL, + ); } else { this.controlPlaneClient .listWorkspaces()