From 33ec800e27b7482aa7b25b149023ccb62d790ec9 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 21 Sep 2021 12:23:14 +0200 Subject: [PATCH] fix(browser-runtime-core): do not call fetchConnectionInfo excessively MONGOSH-995 --- .../browser-runtime-core/src/open-context-runtime.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/browser-runtime-core/src/open-context-runtime.ts b/packages/browser-runtime-core/src/open-context-runtime.ts index 3abba1746f..72bb9632be 100644 --- a/packages/browser-runtime-core/src/open-context-runtime.ts +++ b/packages/browser-runtime-core/src/open-context-runtime.ts @@ -33,7 +33,7 @@ export class OpenContextRuntime implements Runtime { private shellEvaluator: ShellEvaluator; private instanceState: ShellInstanceState; private evaluationListener: RuntimeEvaluationListener | null = null; - private updatedConnectionInfo = false; + private updatedConnectionInfoPromise: Promise | null = null; constructor( serviceProvider: ServiceProvider, @@ -49,9 +49,9 @@ export class OpenContextRuntime implements Runtime { async getCompletions(code: string): Promise { if (!this.autocompleter) { - await this.instanceState.fetchConnectionInfo(); - this.updatedConnectionInfo = true; this.autocompleter = new ShellApiAutocompleter(this.instanceState.getAutocompleteParameters()); + this.updatedConnectionInfoPromise ??= this.instanceState.fetchConnectionInfo(); + await this.updatedConnectionInfoPromise; } return this.autocompleter.getCompletions(code); @@ -76,10 +76,8 @@ export class OpenContextRuntime implements Runtime { } async getShellPrompt(): Promise { - if (!this.updatedConnectionInfo) { - await this.instanceState.fetchConnectionInfo(); - this.updatedConnectionInfo = true; - } + this.updatedConnectionInfoPromise ??= this.instanceState.fetchConnectionInfo(); + await this.updatedConnectionInfoPromise; return await this.instanceState.getDefaultPrompt(); } }