Skip to content

Commit 4bdf579

Browse files
committed
Merge branch 'aeisenberg/analysis-results-on-restart' into aeisenberg/codeSnippet-handling
2 parents 371e83b + 67336a2 commit 4bdf579

4 files changed

Lines changed: 15 additions & 20 deletions

File tree

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,17 @@ export class AnalysesResultsManager {
163163
}
164164

165165

166-
public async loadDownloadedArtifacts(
166+
public async loadDownloadedAnalyses(
167167
allAnalysesToCheck: AnalysisSummary[]
168168
) {
169-
const allDownloadedAnalyses = await asyncFilter(allAnalysesToCheck, x => this.isAnalysisDownloadedNotInMemory(x));
169+
170+
// Find all analyses that are already downloaded.
171+
const allDownloadedAnalyses = await asyncFilter(allAnalysesToCheck, x => this.isAnalysisDownloaded(x));
172+
// Now, ensure that all of these analyses are in memory. Some may already be in memory. These are ignored.
170173
await this.loadAnalysesResults(allDownloadedAnalyses);
171174
}
172175

173-
private async isAnalysisDownloadedNotInMemory(analysis: AnalysisSummary): Promise<boolean> {
174-
const queryId = analysis.downloadLink.queryId;
175-
const resultsForQuery = this.internalGetAnalysesResults(queryId);
176-
const analysisResults = resultsForQuery.find(r => r.nwo === analysis.nwo);
177-
if (analysisResults) {
178-
// We already have the results for this analysis in memory, no need to check further.
179-
return false;
180-
}
181-
182-
// Check if the analysis results are already downloaded, but not in memory
176+
private async isAnalysisDownloaded(analysis: AnalysisSummary): Promise<boolean> {
183177
return await fs.pathExists(createDownloadPath(this.storagePath, analysis.downloadLink));
184178
}
185179

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ export class RemoteQueriesInterfaceManager {
4646
this.getPanel().reveal(undefined, true);
4747

4848
await this.waitForPanelLoaded();
49-
const model = await this.buildViewModel(query, queryResult);
49+
const model = this.buildViewModel(query, queryResult);
5050
await this.postMessage({
5151
t: 'setRemoteQueryResult',
5252
queryResult: model
5353
});
5454

5555
// Ensure all pre-downloaded artifacts are loaded into memory
56-
await this.analysesResultsManager.loadDownloadedArtifacts(model.analysisSummaries);
56+
await this.analysesResultsManager.loadDownloadedAnalyses(model.analysisSummaries);
5757

5858
await this.setAnalysisResults(this.analysesResultsManager.getAnalysesResults(queryResult.queryId));
5959
}
@@ -66,7 +66,7 @@ export class RemoteQueriesInterfaceManager {
6666
* @param queryResult The result of the query.
6767
* @returns A fully created view model.
6868
*/
69-
private async buildViewModel(query: RemoteQuery, queryResult: RemoteQueryResult): Promise<RemoteQueryResultViewModel> {
69+
private buildViewModel(query: RemoteQuery, queryResult: RemoteQueryResult): RemoteQueryResultViewModel {
7070
const queryFileName = path.basename(query.queryFilePath);
7171
const totalResultCount = queryResult.analysisSummaries.reduce((acc, cur) => acc + cur.resultCount, 0);
7272
const executionDuration = this.getDuration(queryResult.executionEndTime, query.executionStartTime);

extensions/ql-vscode/src/vscode-tests/no-workspace/download-link.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path';
44

55
import { DownloadLink, createDownloadPath } from '../../remote-queries/download-link';
66

7-
describe('toDownloadPath', () => {
7+
describe('createDownloadPath', () => {
88
it('should return the correct path', () => {
99
const downloadLink: DownloadLink = {
1010
id: 'abc',

extensions/ql-vscode/src/vscode-tests/no-workspace/remote-query-history.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,18 @@ describe('Remote queries and query history manager', function() {
337337
// Load remoteQueryResult0.analysisSummaries[1] into memory
338338
await arm.downloadAnalysisResults(remoteQueryResult0.analysisSummaries[1], () => Promise.resolve());
339339

340-
expect(await (arm as any).isAnalysisDownloadedNotInMemory(remoteQueryResult0.analysisSummaries[0])).to.be.true;
340+
// on disk
341+
expect(await (arm as any).isAnalysisDownloaded(remoteQueryResult0.analysisSummaries[0])).to.be.true;
341342

342343
// in memory
343-
expect(await (arm as any).isAnalysisDownloadedNotInMemory(remoteQueryResult0.analysisSummaries[1])).to.be.false;
344+
expect(await (arm as any).isAnalysisDownloaded(remoteQueryResult0.analysisSummaries[1])).to.be.true;
344345

345346
// not downloaded
346-
expect(await (arm as any).isAnalysisDownloadedNotInMemory(remoteQueryResult0.analysisSummaries[2])).to.be.false;
347+
expect(await (arm as any).isAnalysisDownloaded(remoteQueryResult0.analysisSummaries[2])).to.be.false;
347348
});
348349

349350
it('should load downloaded artifacts', async () => {
350-
await arm.loadDownloadedArtifacts(remoteQueryResult0.analysisSummaries);
351+
await arm.loadDownloadedAnalyses(remoteQueryResult0.analysisSummaries);
351352
const queryId = rawQueryHistory[0].queryId;
352353
const analysesResultsNwos = arm.getAnalysesResults(queryId).map(ar => ar.nwo).sort();
353354
expect(analysesResultsNwos[0]).to.eq('github/vscode-codeql');

0 commit comments

Comments
 (0)