@@ -64,6 +64,7 @@ import kotlinx.coroutines.cancel
6464import kotlinx.coroutines.delay
6565import kotlinx.coroutines.isActive
6666import kotlinx.coroutines.launch
67+ import kotlinx.coroutines.runBlocking
6768import kotlinx.coroutines.withContext
6869import org.zeroturnaround.exec.ProcessExecutor
6970import java.awt.Component
@@ -399,12 +400,20 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
399400
400401 val authTask = object : Task .Modal (null , CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.cli.downloader.dialog.title" ), false ) {
401402 override fun run (pi : ProgressIndicator ) {
402-
403403 pi.apply {
404404 isIndeterminate = false
405- text = " Downloading coder cli ..."
405+ text = " Retrieving Workspaces ..."
406406 fraction = 0.1
407407 }
408+ runBlocking {
409+ loadWorkspaces()
410+ }
411+
412+ pi.apply {
413+ isIndeterminate = false
414+ text = " Downloading Coder CLI..."
415+ fraction = 0.3
416+ }
408417
409418 cliManager.downloadCLI()
410419 if (getOS() != OS .WINDOWS ) {
@@ -413,7 +422,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
413422 logger.info(" chmod +x ${cliManager.localCli.toAbsolutePath()} $chmodOutput " )
414423 }
415424 pi.apply {
416- text = " Configuring coder cli ..."
425+ text = " Configuring Coder CLI ..."
417426 fraction = 0.5
418427 }
419428
@@ -424,7 +433,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
424433 logger.info(" Result of `${localWizardModel.localCliPath} config-ssh --yes --use-previous-options`: $sshConfigOutput " )
425434
426435 pi.apply {
427- text = " Remove old coder cli versions..."
436+ text = " Remove old Coder CLI versions..."
428437 fraction = 0.9
429438 }
430439 cliManager.removeOldCli()
@@ -467,35 +476,50 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
467476
468477 poller = cs.launch {
469478 while (isActive) {
470- loadWorkspaces()
471479 delay(5000 )
480+ loadWorkspaces()
472481 }
473482 }
474483 }
475484
476485 private suspend fun loadWorkspaces () {
477- val workspaceList = withContext(Dispatchers .IO ) {
486+ withContext(Dispatchers .IO ) {
487+ val timeBeforeRequestingWorkspaces = System .currentTimeMillis()
478488 try {
479- return @withContext coderClient.workspaces().collectAgents()
489+ val ws = coderClient.workspaces()
490+ val timeAfterRequestingWorkspaces = System .currentTimeMillis()
491+ logger.info(" Retrieving the workspaces took: ${timeAfterRequestingWorkspaces - timeBeforeRequestingWorkspaces} millis" )
492+ ws.resolveAndDisplayAgents()
480493 } catch (e: Exception ) {
481494 logger.error(" Could not retrieve workspaces for ${coderClient.me.username} on ${coderClient.coderURL} . Reason: $e " )
482- emptyList()
483495 }
484496 }
497+ }
485498
486- withContext(Dispatchers .Main ) {
487- val selectedWorkspace = tableOfWorkspaces.selectedObject?.name
488- listTableModelOfWorkspaces.items = workspaceList
489- if (selectedWorkspace != null ) {
490- tableOfWorkspaces.selectItem(selectedWorkspace)
499+ private fun List<Workspace>.resolveAndDisplayAgents () {
500+ this .forEach { workspace ->
501+ cs.launch(Dispatchers .IO ) {
502+ val timeBeforeRequestingAgents = System .currentTimeMillis()
503+ workspace.agentModels().forEach { am ->
504+ withContext(Dispatchers .Main ) {
505+ val selectedWorkspace = tableOfWorkspaces.selectedObject?.name
506+ if (listTableModelOfWorkspaces.indexOf(am) >= 0 ) {
507+ val index = listTableModelOfWorkspaces.indexOf(am)
508+ listTableModelOfWorkspaces.setItem(index, am)
509+ } else {
510+ listTableModelOfWorkspaces.addRow(am)
511+ }
512+ if (selectedWorkspace != null ) {
513+ tableOfWorkspaces.selectItem(selectedWorkspace)
514+ }
515+ }
516+ }
517+ val timeAfterRequestingAgents = System .currentTimeMillis()
518+ logger.info(" Retrieving the agents for ${workspace.name} took: ${timeAfterRequestingAgents - timeBeforeRequestingAgents} millis" )
491519 }
492520 }
493521 }
494522
495- private fun List<Workspace>.collectAgents (): List <WorkspaceAgentModel > {
496- return this .flatMap { it.agentModels() }.toList()
497- }
498-
499523 private fun Workspace.agentModels (): List <WorkspaceAgentModel > {
500524 return try {
501525 val agents = coderClient.workspaceAgentsByTemplate(this )
0 commit comments