From 2c7e2f4b7f782c9b61f5f8ba7e205fb79b176bc8 Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Thu, 14 Apr 2022 14:54:42 -0700 Subject: [PATCH] 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. --- .../remote-queries/remote-queries-interface.ts | 18 ++++++++++++------ .../remote-queries/remote-queries-manager.ts | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/extensions/ql-vscode/src/remote-queries/remote-queries-interface.ts b/extensions/ql-vscode/src/remote-queries/remote-queries-interface.ts index 2af164d71b9..9ddc91f72e6 100644 --- a/extensions/ql-vscode/src/remote-queries/remote-queries-interface.ts +++ b/extensions/ql-vscode/src/remote-queries/remote-queries-interface.ts @@ -30,6 +30,7 @@ import { AnalysisResults } from './shared/analysis-result'; export class RemoteQueriesInterfaceManager { private panel: WebviewPanel | undefined; private panelLoaded = false; + private currentQueryId: string | undefined; private panelLoadedCallBacks: (() => void)[] = []; constructor( @@ -47,6 +48,8 @@ export class RemoteQueriesInterfaceManager { await this.waitForPanelLoaded(); const model = this.buildViewModel(query, queryResult); + this.currentQueryId = queryResult.queryId; + await this.postMessage({ t: 'setRemoteQueryResult', queryResult: model @@ -55,7 +58,7 @@ export class RemoteQueriesInterfaceManager { // Ensure all pre-downloaded artifacts are loaded into memory await this.analysesResultsManager.loadDownloadedAnalyses(model.analysisSummaries); - await this.setAnalysisResults(this.analysesResultsManager.getAnalysesResults(queryResult.queryId)); + await this.setAnalysisResults(this.analysesResultsManager.getAnalysesResults(queryResult.queryId), queryResult.queryId); } /** @@ -111,6 +114,7 @@ export class RemoteQueriesInterfaceManager { this.panel.onDidDispose( () => { this.panel = undefined; + this.currentQueryId = undefined; }, null, ctx.subscriptions @@ -212,23 +216,25 @@ export class RemoteQueriesInterfaceManager { } private async downloadAnalysisResults(msg: RemoteQueryDownloadAnalysisResultsMessage): Promise { + const queryId = this.currentQueryId; await this.analysesResultsManager.downloadAnalysisResults( msg.analysisSummary, - results => this.setAnalysisResults(results)); + results => this.setAnalysisResults(results, queryId)); } private async downloadAllAnalysesResults(msg: RemoteQueryDownloadAllAnalysesResultsMessage): Promise { + const queryId = this.currentQueryId; await this.analysesResultsManager.loadAnalysesResults( msg.analysisSummaries, undefined, - results => this.setAnalysisResults(results)); + results => this.setAnalysisResults(results, queryId)); } - public async setAnalysisResults(analysesResults: AnalysisResults[]): Promise { - if (this.panel?.active) { + public async setAnalysisResults(analysesResults: AnalysisResults[], queryId: string | undefined): Promise { + if (this.panel?.active && this.currentQueryId === queryId) { await this.postMessage({ t: 'setAnalysesResults', - analysesResults: analysesResults + analysesResults }); } } diff --git a/extensions/ql-vscode/src/remote-queries/remote-queries-manager.ts b/extensions/ql-vscode/src/remote-queries/remote-queries-manager.ts index 76332ffc704..62609715a7f 100644 --- a/extensions/ql-vscode/src/remote-queries/remote-queries-manager.ts +++ b/extensions/ql-vscode/src/remote-queries/remote-queries-manager.ts @@ -196,7 +196,7 @@ export class RemoteQueriesManager extends DisposableObject { await this.analysesResultsManager.loadAnalysesResults( analysesToDownload, token, - results => this.interfaceManager.setAnalysisResults(results)); + results => this.interfaceManager.setAnalysisResults(results, queryResult.queryId)); } private mapQueryResult(executionEndTime: number, resultIndex: RemoteQueryResultIndex, queryId: string): RemoteQueryResult {