Skip to content

Commit 2c7e2f4

Browse files
committed
Avoid loading wrong results into an open window
This fixes a bug where an open results view will accumulate results from other queries who have their results downloaded while this view is open. The fix is to ensure that the results view for the query is open when some results are downloaded.
1 parent 77024f0 commit 2c7e2f4

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

extensions/ql-vscode/src/remote-queries/remote-queries-interface.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { AnalysisResults } from './shared/analysis-result';
3030
export class RemoteQueriesInterfaceManager {
3131
private panel: WebviewPanel | undefined;
3232
private panelLoaded = false;
33+
private currentQueryId: string | undefined;
3334
private panelLoadedCallBacks: (() => void)[] = [];
3435

3536
constructor(
@@ -47,6 +48,8 @@ export class RemoteQueriesInterfaceManager {
4748

4849
await this.waitForPanelLoaded();
4950
const model = this.buildViewModel(query, queryResult);
51+
this.currentQueryId = queryResult.queryId;
52+
5053
await this.postMessage({
5154
t: 'setRemoteQueryResult',
5255
queryResult: model
@@ -55,7 +58,7 @@ export class RemoteQueriesInterfaceManager {
5558
// Ensure all pre-downloaded artifacts are loaded into memory
5659
await this.analysesResultsManager.loadDownloadedAnalyses(model.analysisSummaries);
5760

58-
await this.setAnalysisResults(this.analysesResultsManager.getAnalysesResults(queryResult.queryId));
61+
await this.setAnalysisResults(this.analysesResultsManager.getAnalysesResults(queryResult.queryId), queryResult.queryId);
5962
}
6063

6164
/**
@@ -111,6 +114,7 @@ export class RemoteQueriesInterfaceManager {
111114
this.panel.onDidDispose(
112115
() => {
113116
this.panel = undefined;
117+
this.currentQueryId = undefined;
114118
},
115119
null,
116120
ctx.subscriptions
@@ -212,23 +216,25 @@ export class RemoteQueriesInterfaceManager {
212216
}
213217

214218
private async downloadAnalysisResults(msg: RemoteQueryDownloadAnalysisResultsMessage): Promise<void> {
219+
const queryId = this.currentQueryId;
215220
await this.analysesResultsManager.downloadAnalysisResults(
216221
msg.analysisSummary,
217-
results => this.setAnalysisResults(results));
222+
results => this.setAnalysisResults(results, queryId));
218223
}
219224

220225
private async downloadAllAnalysesResults(msg: RemoteQueryDownloadAllAnalysesResultsMessage): Promise<void> {
226+
const queryId = this.currentQueryId;
221227
await this.analysesResultsManager.loadAnalysesResults(
222228
msg.analysisSummaries,
223229
undefined,
224-
results => this.setAnalysisResults(results));
230+
results => this.setAnalysisResults(results, queryId));
225231
}
226232

227-
public async setAnalysisResults(analysesResults: AnalysisResults[]): Promise<void> {
228-
if (this.panel?.active) {
233+
public async setAnalysisResults(analysesResults: AnalysisResults[], queryId: string | undefined): Promise<void> {
234+
if (this.panel?.active && this.currentQueryId === queryId) {
229235
await this.postMessage({
230236
t: 'setAnalysesResults',
231-
analysesResults: analysesResults
237+
analysesResults
232238
});
233239
}
234240
}

extensions/ql-vscode/src/remote-queries/remote-queries-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class RemoteQueriesManager extends DisposableObject {
196196
await this.analysesResultsManager.loadAnalysesResults(
197197
analysesToDownload,
198198
token,
199-
results => this.interfaceManager.setAnalysisResults(results));
199+
results => this.interfaceManager.setAnalysisResults(results, queryResult.queryId));
200200
}
201201

202202
private mapQueryResult(executionEndTime: number, resultIndex: RemoteQueryResultIndex, queryId: string): RemoteQueryResult {

0 commit comments

Comments
 (0)