Skip to content

Commit 6a636ba

Browse files
authored
Remove historyItemId for variant analyses (#1651)
1 parent 9e92d0c commit 6a636ba

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

extensions/ql-vscode/src/query-history-info.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@ export function getRawQueryName(item: QueryHistoryInfo): string {
2020
}
2121
}
2222

23-
export function getQueryHistoryItemId(item: QueryHistoryInfo): string {
23+
/**
24+
* Gets an identifier for the query history item which could be
25+
* a local/remote query or a variant analysis. This id isn't guaranteed
26+
* to be unique for each item in the query history.
27+
* @param item the history item.
28+
* @returns the id of the query or variant analysis.
29+
*/
30+
export function getQueryId(item: QueryHistoryInfo): string {
2431
switch (item.t) {
2532
case 'local':
2633
return item.initialInfo.id;
2734
case 'remote':
2835
return item.queryId;
2936
case 'variant-analysis':
30-
return item.historyItemId;
37+
return item.variantAnalysis.id.toString();
3138
default:
3239
assertNever(item);
3340
}
@@ -48,18 +55,18 @@ export function getQueryText(item: QueryHistoryInfo): string {
4855

4956
export function buildRepoLabel(item: RemoteQueryHistoryItem | VariantAnalysisHistoryItem): string {
5057
if (item.t === 'remote') {
51-
// Return the number of repositories queried if available. Otherwise, use the controller repository name.
52-
const repositoryCount = item.remoteQuery.repositoryCount;
53-
54-
if (repositoryCount) {
55-
return pluralize(repositoryCount, 'repository', 'repositories');
56-
}
57-
return `${item.remoteQuery.controllerRepository.owner}/${item.remoteQuery.controllerRepository.name}`;
58-
} else if (item.t === 'variant-analysis') {
59-
const totalScannedRepositoryCount = item.variantAnalysis.scannedRepos?.length ?? 0;
60-
const completedRepositoryCount = item.variantAnalysis.scannedRepos?.filter(repo => hasRepoScanCompleted(repo)).length ?? 0;
58+
// Return the number of repositories queried if available. Otherwise, use the controller repository name.
59+
const repositoryCount = item.remoteQuery.repositoryCount;
6160

62-
return `${completedRepositoryCount}/${pluralize(totalScannedRepositoryCount, 'repository', 'repositories')}`; // e.g. "2/3 repositories"
61+
if (repositoryCount) {
62+
return pluralize(repositoryCount, 'repository', 'repositories');
63+
}
64+
return `${item.remoteQuery.controllerRepository.owner}/${item.remoteQuery.controllerRepository.name}`;
65+
} else if (item.t === 'variant-analysis') {
66+
const totalScannedRepositoryCount = item.variantAnalysis.scannedRepos?.length ?? 0;
67+
const completedRepositoryCount = item.variantAnalysis.scannedRepos?.filter(repo => hasRepoScanCompleted(repo)).length ?? 0;
68+
69+
return `${completedRepositoryCount}/${pluralize(totalScannedRepositoryCount, 'repository', 'repositories')}`; // e.g. "2/3 repositories"
6370
} else {
6471
assertNever(item);
6572
}

extensions/ql-vscode/src/query-history.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { commandRunner } from './commandRunner';
3131
import { ONE_HOUR_IN_MS, TWO_HOURS_IN_MS } from './pure/time';
3232
import { assertNever, getErrorMessage, getErrorStack } from './pure/helpers-pure';
3333
import { CompletedLocalQueryInfo, LocalQueryInfo } from './query-results';
34-
import { getQueryHistoryItemId, getQueryText, QueryHistoryInfo } from './query-history-info';
34+
import { getQueryId, getQueryText, QueryHistoryInfo } from './query-history-info';
3535
import { DatabaseManager } from './databases';
3636
import { registerQueryHistoryScrubber } from './query-history-scrubber';
3737
import { QueryStatus, variantAnalysisStatusToQueryStatus } from './query-status';
@@ -51,7 +51,6 @@ import { EvalLogData, parseViewerData } from './pure/log-summary-parser';
5151
import { QueryWithResults } from './run-queries-shared';
5252
import { QueryRunner } from './queryRunner';
5353
import { VariantAnalysisManager } from './remote-queries/variant-analysis-manager';
54-
import { nanoid } from 'nanoid';
5554
import { VariantAnalysisHistoryItem } from './remote-queries/variant-analysis-history-item';
5655
import { getTotalResultCount } from './remote-queries/shared/variant-analysis';
5756

@@ -606,7 +605,6 @@ export class QueryHistoryManager extends DisposableObject {
606605
t: 'variant-analysis',
607606
status: QueryStatus.InProgress,
608607
completed: false,
609-
historyItemId: nanoid(),
610608
variantAnalysis,
611609
});
612610

@@ -1109,7 +1107,7 @@ export class QueryHistoryManager extends DisposableObject {
11091107
queryText: encodeURIComponent(getQueryText(finalSingleItem)),
11101108
});
11111109

1112-
const queryId = getQueryHistoryItemId(finalSingleItem);
1110+
const queryId = getQueryId(finalSingleItem);
11131111

11141112
const uri = Uri.parse(
11151113
`codeql:${queryId}.ql?${params.toString()}`, true

extensions/ql-vscode/src/remote-queries/variant-analysis-history-item.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export interface VariantAnalysisHistoryItem {
1010
resultCount?: number;
1111
status: QueryStatus;
1212
completed: boolean;
13-
readonly historyItemId: string,
1413
variantAnalysis: VariantAnalysis;
1514
userSpecifiedLabel?: string;
1615
}

extensions/ql-vscode/test/pure-tests/query-history-info.test.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22

33
import { QueryStatus } from '../../src/query-status';
4-
import { buildRepoLabel, getQueryHistoryItemId, getQueryText, getRawQueryName } from '../../src/query-history-info';
4+
import { buildRepoLabel, getQueryId, getQueryText, getRawQueryName } from '../../src/query-history-info';
55
import { VariantAnalysisHistoryItem } from '../../src/remote-queries/variant-analysis-history-item';
66
import { createMockVariantAnalysis } from '../../src/vscode-tests/factories/remote-queries/shared/variant-analysis';
77
import { createMockScannedRepos } from '../../src/vscode-tests/factories/remote-queries/shared/scanned-repositories';
@@ -19,7 +19,6 @@ describe('Query history info', () => {
1919
t: 'variant-analysis',
2020
status: QueryStatus.InProgress,
2121
completed: false,
22-
historyItemId: 'abc123',
2322
variantAnalysis: createMockVariantAnalysis(
2423
VariantAnalysisStatus.InProgress,
2524
createMockScannedRepos([
@@ -51,23 +50,23 @@ describe('Query history info', () => {
5150
});
5251
});
5352

54-
describe('getQueryHistoryItemId', () => {
53+
describe('getQueryId', () => {
5554
it('should get the ID for local history items', () => {
56-
const historyItemId = getQueryHistoryItemId(localQueryHistoryItem);
55+
const historyItemId = getQueryId(localQueryHistoryItem);
5756

5857
expect(historyItemId).to.equal(localQueryHistoryItem.initialInfo.id);
5958
});
6059

6160
it('should get the ID for remote query history items', () => {
62-
const historyItemId = getQueryHistoryItemId(remoteQueryHistoryItem);
61+
const historyItemId = getQueryId(remoteQueryHistoryItem);
6362

6463
expect(historyItemId).to.equal(remoteQueryHistoryItem.queryId);
6564
});
6665

6766
it('should get the ID for variant analysis history items', () => {
68-
const historyItemId = getQueryHistoryItemId(variantAnalysisHistoryItem);
67+
const historyItemId = getQueryId(variantAnalysisHistoryItem);
6968

70-
expect(historyItemId).to.equal(variantAnalysisHistoryItem.historyItemId);
69+
expect(historyItemId).to.equal(variantAnalysisHistoryItem.variantAnalysis.id.toString());
7170
});
7271
});
7372

@@ -100,10 +99,10 @@ describe('Query history info', () => {
10099
expect(repoLabel).to.equal(expectedRepoLabel);
101100
});
102101
it('should return number of repositories when `repositoryCount` is non-zero', () => {
103-
const remoteQueryHistoryItem2 = createMockRemoteQueryHistoryItem({repositoryCount: 3});
102+
const remoteQueryHistoryItem2 = createMockRemoteQueryHistoryItem({ repositoryCount: 3 });
104103
const repoLabel2 = buildRepoLabel(remoteQueryHistoryItem2);
105104
const expectedRepoLabel2 = '3 repositories';
106-
105+
107106
expect(repoLabel2).to.equal(expectedRepoLabel2);
108107
});
109108
});
@@ -113,7 +112,6 @@ describe('Query history info', () => {
113112
t: 'variant-analysis',
114113
status: QueryStatus.InProgress,
115114
completed: false,
116-
historyItemId: 'abc123',
117115
variantAnalysis: createMockVariantAnalysis(
118116
VariantAnalysisStatus.InProgress,
119117
createMockScannedRepos([])
@@ -128,7 +126,6 @@ describe('Query history info', () => {
128126
t: 'variant-analysis',
129127
status: QueryStatus.InProgress,
130128
completed: false,
131-
historyItemId: 'abc123',
132129
variantAnalysis: createMockVariantAnalysis(
133130
VariantAnalysisStatus.InProgress,
134131
createMockScannedRepos([
@@ -142,9 +139,9 @@ describe('Query history info', () => {
142139
});
143140
it('should return label when `totalScannedRepositoryCount` is greater than 1', () => {
144141
const repoLabel = buildRepoLabel(variantAnalysisHistoryItem);
145-
142+
146143
expect(repoLabel).to.equal('2/4 repositories');
147144
});
148145
});
149-
});
146+
});
150147
});

0 commit comments

Comments
 (0)