Skip to content

Commit 0df8dab

Browse files
authored
perf(codecatalyst): avoid extra service call during connect #3294
Problem: openDevEnv() calls getDevEnvironment() even though prepareDevEnvConnection() already has that info. Solution: Use the object from prepareDevEnvConnection() and drop the extra call to getDevEnvironment().
1 parent 12e6417 commit 0df8dab

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/codecatalyst/model.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ interface DevEnvConnection {
182182
readonly hostname: string
183183
readonly envProvider: EnvProvider
184184
readonly SessionProcess: typeof ChildProcess
185+
readonly devenv: DevEnvironment
185186
}
186187

187188
export async function prepareDevEnvConnection(
@@ -209,6 +210,7 @@ export async function prepareDevEnvConnection(
209210

210211
return {
211212
hostname,
213+
devenv: runningDevEnv,
212214
envProvider,
213215
sshPath: ssh,
214216
vscPath: vsc,
@@ -228,17 +230,12 @@ export async function openDevEnv(
228230
devenv: DevEnvironmentId,
229231
targetPath?: string
230232
): Promise<void> {
231-
const { SessionProcess, vscPath } = await prepareDevEnvConnection(client, devenv, { topic: 'connect' })
233+
const env = await prepareDevEnvConnection(client, devenv, { topic: 'connect' })
232234
if (!targetPath) {
233-
const env = await client.getDevEnvironment({
234-
spaceName: devenv.org.name,
235-
projectName: devenv.project.name,
236-
id: devenv.id,
237-
})
238-
const repo = env.repositories.length == 1 ? env.repositories[0].repositoryName : undefined
235+
const repo = env.devenv.repositories.length == 1 ? env.devenv.repositories[0].repositoryName : undefined
239236
targetPath = repo ? `/projects/${repo}` : '/projects'
240237
}
241-
await startVscodeRemote(SessionProcess, getHostNameFromEnv(devenv), targetPath, vscPath)
238+
await startVscodeRemote(env.SessionProcess, getHostNameFromEnv(env.devenv), targetPath, env.vscPath)
242239
}
243240

244241
// The "codecatalyst_connect" metric should really be splt into two parts:

0 commit comments

Comments
 (0)