Skip to content

Commit d6336b6

Browse files
authored
fix(browser-runtime-core): do not call fetchConnectionInfo excessively MONGOSH-995 (#1112)
1 parent f3f50f5 commit d6336b6

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/browser-runtime-core/src/open-context-runtime.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class OpenContextRuntime implements Runtime {
3333
private shellEvaluator: ShellEvaluator;
3434
private instanceState: ShellInstanceState;
3535
private evaluationListener: RuntimeEvaluationListener | null = null;
36-
private updatedConnectionInfo = false;
36+
private updatedConnectionInfoPromise: Promise<void> | null = null;
3737

3838
constructor(
3939
serviceProvider: ServiceProvider,
@@ -49,9 +49,9 @@ export class OpenContextRuntime implements Runtime {
4949

5050
async getCompletions(code: string): Promise<Completion[]> {
5151
if (!this.autocompleter) {
52-
await this.instanceState.fetchConnectionInfo();
53-
this.updatedConnectionInfo = true;
5452
this.autocompleter = new ShellApiAutocompleter(this.instanceState.getAutocompleteParameters());
53+
this.updatedConnectionInfoPromise ??= this.instanceState.fetchConnectionInfo();
54+
await this.updatedConnectionInfoPromise;
5555
}
5656

5757
return this.autocompleter.getCompletions(code);
@@ -76,10 +76,8 @@ export class OpenContextRuntime implements Runtime {
7676
}
7777

7878
async getShellPrompt(): Promise<string> {
79-
if (!this.updatedConnectionInfo) {
80-
await this.instanceState.fetchConnectionInfo();
81-
this.updatedConnectionInfo = true;
82-
}
79+
this.updatedConnectionInfoPromise ??= this.instanceState.fetchConnectionInfo();
80+
await this.updatedConnectionInfoPromise;
8381
return await this.instanceState.getDefaultPrompt();
8482
}
8583
}

0 commit comments

Comments
 (0)