Skip to content

Commit c04893c

Browse files
committed
Add cache of query schemas to results view
1 parent ffe8248 commit c04893c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

extensions/ql-vscode/src/language-support/contextual/cached-operation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,10 @@ export class CachedOperation<S extends unknown[], U> {
6969
this.inProgressCallbacks.delete(t);
7070
}
7171
}
72+
73+
reset() {
74+
this.cached.clear();
75+
this.lru.length = 0;
76+
this.inProgressCallbacks.clear();
77+
}
7278
}

extensions/ql-vscode/src/local-queries/results-view.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import type { App } from "../common/app";
7575
import type { Disposable } from "../common/disposable-object";
7676
import type { RawResultSet } from "../common/raw-result-types";
7777
import type { BqrsResultSetSchema } from "../common/bqrs-cli-types";
78+
import { CachedOperation } from "../language-support/contextual/cached-operation";
7879

7980
/**
8081
* results-view.ts
@@ -177,6 +178,8 @@ export class ResultsView extends AbstractWebview<
177178
// Event listeners that should be disposed of when the view is disposed.
178179
private disposableEventListeners: Disposable[] = [];
179180

181+
private schemaCache: CachedOperation<[], BqrsResultSetSchema[]>;
182+
180183
constructor(
181184
app: App,
182185
private databaseManager: DatabaseManager,
@@ -206,6 +209,10 @@ export class ResultsView extends AbstractWebview<
206209
}
207210
}),
208211
);
212+
213+
this.schemaCache = new CachedOperation(
214+
this.getResultSetSchemasImpl.bind(this),
215+
);
209216
}
210217

211218
public getCommands(): ResultsViewCommands {
@@ -420,6 +427,7 @@ export class ResultsView extends AbstractWebview<
420427
);
421428
return;
422429
}
430+
this.schemaCache.reset();
423431
// Notify the webview that it should expect new results.
424432
await this.postMessage({ t: "resultsUpdating" });
425433
await this._displayedQuery.completedQuery.updateSortState(
@@ -610,6 +618,12 @@ export class ResultsView extends AbstractWebview<
610618
selectedTable = "",
611619
): Promise<BqrsResultSetSchema[]> {
612620
const resultsPath = completedQuery.getResultsPath(selectedTable);
621+
return this.schemaCache.get(resultsPath);
622+
}
623+
624+
private async getResultSetSchemasImpl(
625+
resultsPath: string,
626+
): Promise<BqrsResultSetSchema[]> {
613627
const schemas = await this.cliServer.bqrsInfo(
614628
resultsPath,
615629
PAGE_SIZE.getValue(),

0 commit comments

Comments
 (0)