Skip to content

Commit fb4d6db

Browse files
committed
Remove remote queries history item
This removes the remote queries history item as a supported history item. This allows us to delete almost all code related to remote queries except for the React view code which will be removed separately. In the query serialization code, we now ignore remote queries.
1 parent 89860d4 commit fb4d6db

24 files changed

+142
-844
lines changed

extensions/ql-vscode/src/extension.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,6 @@ async function activateWithInstalledDistribution(
652652

653653
void extLogger.log("Initializing query history.");
654654
const qhm = new QueryHistoryManager(
655-
app,
656655
qs,
657656
dbm,
658657
localQueryResultsView,

extensions/ql-vscode/src/query-history/history-item-label-provider.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
getRawQueryName,
88
QueryHistoryInfo,
99
} from "./query-history-info";
10-
import { RemoteQueryHistoryItem } from "../remote-queries/remote-query-history-item";
1110
import { VariantAnalysisHistoryItem } from "./variant-analysis-history-item";
1211
import { assertNever } from "../pure/helpers-pure";
1312
import { pluralize } from "../pure/word";
@@ -34,9 +33,6 @@ export class HistoryItemLabelProvider {
3433
case "local":
3534
replacements = this.getLocalInterpolateReplacements(item);
3635
break;
37-
case "remote":
38-
replacements = this.getRemoteInterpolateReplacements(item);
39-
break;
4036
case "variant-analysis":
4137
replacements = this.getVariantAnalysisInterpolateReplacements(item);
4238
break;
@@ -92,25 +88,6 @@ export class HistoryItemLabelProvider {
9288
};
9389
}
9490

95-
private getRemoteInterpolateReplacements(
96-
item: RemoteQueryHistoryItem,
97-
): InterpolateReplacements {
98-
const resultCount = item.resultCount
99-
? `(${pluralize(item.resultCount, "result", "results")})`
100-
: "";
101-
return {
102-
t: new Date(item.remoteQuery.executionStartTime).toLocaleString(
103-
env.language,
104-
),
105-
q: `${item.remoteQuery.queryName} (${item.remoteQuery.language})`,
106-
d: buildRepoLabel(item),
107-
r: resultCount,
108-
s: humanizeQueryStatus(item.status),
109-
f: basename(item.remoteQuery.queryFilePath),
110-
"%": "%",
111-
};
112-
}
113-
11491
private getVariantAnalysisInterpolateReplacements(
11592
item: VariantAnalysisHistoryItem,
11693
): InterpolateReplacements {

extensions/ql-vscode/src/query-history/history-tree-data-provider.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ export class HistoryTreeDataProvider
236236
switch (item.t) {
237237
case "local":
238238
return item.initialInfo.start.getTime();
239-
case "remote":
240-
return item.remoteQuery.executionStartTime;
241239
case "variant-analysis":
242240
return item.variantAnalysis.executionStartTime;
243241
default:
Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { RemoteQueryHistoryItem } from "../remote-queries/remote-query-history-item";
21
import { VariantAnalysisHistoryItem } from "./variant-analysis-history-item";
32
import { LocalQueryInfo } from "../query-results";
43
import { assertNever } from "../pure/helpers-pure";
@@ -8,17 +7,12 @@ import {
87
getActionsWorkflowRunUrl as getVariantAnalysisActionsWorkflowRunUrl,
98
} from "../remote-queries/shared/variant-analysis";
109

11-
export type QueryHistoryInfo =
12-
| LocalQueryInfo
13-
| RemoteQueryHistoryItem
14-
| VariantAnalysisHistoryItem;
10+
export type QueryHistoryInfo = LocalQueryInfo | VariantAnalysisHistoryItem;
1511

1612
export function getRawQueryName(item: QueryHistoryInfo): string {
1713
switch (item.t) {
1814
case "local":
1915
return item.getQueryName();
20-
case "remote":
21-
return item.remoteQuery.queryName;
2216
case "variant-analysis":
2317
return item.variantAnalysis.query.name;
2418
default:
@@ -37,8 +31,6 @@ export function getQueryId(item: QueryHistoryInfo): string {
3731
switch (item.t) {
3832
case "local":
3933
return item.initialInfo.id;
40-
case "remote":
41-
return item.queryId;
4234
case "variant-analysis":
4335
return item.variantAnalysis.id.toString();
4436
default:
@@ -50,56 +42,30 @@ export function getQueryText(item: QueryHistoryInfo): string {
5042
switch (item.t) {
5143
case "local":
5244
return item.initialInfo.queryText;
53-
case "remote":
54-
return item.remoteQuery.queryText;
5545
case "variant-analysis":
5646
return item.variantAnalysis.query.text;
5747
default:
5848
assertNever(item);
5949
}
6050
}
6151

62-
export function buildRepoLabel(
63-
item: RemoteQueryHistoryItem | VariantAnalysisHistoryItem,
64-
): string {
65-
if (item.t === "remote") {
66-
// Return the number of repositories queried if available. Otherwise, use the controller repository name.
67-
const repositoryCount = item.remoteQuery.repositoryCount;
68-
69-
if (repositoryCount) {
70-
return pluralize(repositoryCount, "repository", "repositories");
71-
}
72-
return `${item.remoteQuery.controllerRepository.owner}/${item.remoteQuery.controllerRepository.name}`;
73-
} else if (item.t === "variant-analysis") {
74-
const totalScannedRepositoryCount =
75-
item.variantAnalysis.scannedRepos?.length ?? 0;
76-
const completedRepositoryCount =
77-
item.variantAnalysis.scannedRepos?.filter((repo) =>
78-
hasRepoScanCompleted(repo),
79-
).length ?? 0;
52+
export function buildRepoLabel(item: VariantAnalysisHistoryItem): string {
53+
const totalScannedRepositoryCount =
54+
item.variantAnalysis.scannedRepos?.length ?? 0;
55+
const completedRepositoryCount =
56+
item.variantAnalysis.scannedRepos?.filter((repo) =>
57+
hasRepoScanCompleted(repo),
58+
).length ?? 0;
8059

81-
return `${completedRepositoryCount}/${pluralize(
82-
totalScannedRepositoryCount,
83-
"repository",
84-
"repositories",
85-
)}`; // e.g. "2/3 repositories"
86-
} else {
87-
assertNever(item);
88-
}
60+
return `${completedRepositoryCount}/${pluralize(
61+
totalScannedRepositoryCount,
62+
"repository",
63+
"repositories",
64+
)}`; // e.g. "2/3 repositories"
8965
}
9066

9167
export function getActionsWorkflowRunUrl(
92-
item: RemoteQueryHistoryItem | VariantAnalysisHistoryItem,
68+
item: VariantAnalysisHistoryItem,
9369
): string {
94-
if (item.t === "remote") {
95-
const {
96-
actionsWorkflowRunId: workflowRunId,
97-
controllerRepository: { owner, name },
98-
} = item.remoteQuery;
99-
return `https://github.com/${owner}/${name}/actions/runs/${workflowRunId}`;
100-
} else if (item.t === "variant-analysis") {
101-
return getVariantAnalysisActionsWorkflowRunUrl(item.variantAnalysis);
102-
} else {
103-
assertNever(item);
104-
}
70+
return getVariantAnalysisActionsWorkflowRunUrl(item.variantAnalysis);
10571
}

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

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ import {
5353
import { pathExists } from "fs-extra";
5454
import { CliVersionConstraint } from "../cli";
5555
import { HistoryItemLabelProvider } from "./history-item-label-provider";
56-
import { cancelRemoteQuery } from "../remote-queries/gh-api/gh-actions-api-client";
57-
import { RemoteQueryHistoryItem } from "../remote-queries/remote-query-history-item";
5856
import { ResultsView } from "../interface";
5957
import { WebviewReveal } from "../interface-utils";
6058
import { EvalLogViewer } from "../eval-log-viewer";
@@ -65,7 +63,6 @@ import { QueryRunner } from "../queryRunner";
6563
import { VariantAnalysisManager } from "../remote-queries/variant-analysis-manager";
6664
import { VariantAnalysisHistoryItem } from "./variant-analysis-history-item";
6765
import { getTotalResultCount } from "../remote-queries/shared/variant-analysis";
68-
import { App } from "../common/app";
6966
import { HistoryTreeDataProvider } from "./history-tree-data-provider";
7067
import { redactableError } from "../pure/errors";
7168

@@ -137,7 +134,6 @@ export class QueryHistoryManager extends DisposableObject {
137134
readonly onDidCompleteQuery = this._onDidCompleteQuery.event;
138135

139136
constructor(
140-
private readonly app: App,
141137
private readonly qs: QueryRunner,
142138
private readonly dbm: DatabaseManager,
143139
private readonly localQueriesResultsView: ResultsView,
@@ -525,9 +521,6 @@ export class QueryHistoryManager extends DisposableObject {
525521
case "local":
526522
queryPath = finalSingleItem.initialInfo.queryPath;
527523
break;
528-
case "remote":
529-
queryPath = finalSingleItem.remoteQuery.queryFilePath;
530-
break;
531524
default:
532525
assertNever(finalSingleItem);
533526
}
@@ -553,12 +546,6 @@ export class QueryHistoryManager extends DisposableObject {
553546
return this.treeDataProvider.getCurrent();
554547
}
555548

556-
getRemoteQueryById(queryId: string): RemoteQueryHistoryItem | undefined {
557-
return this.treeDataProvider.allHistory.find(
558-
(i) => i.t === "remote" && i.queryId === queryId,
559-
) as RemoteQueryHistoryItem;
560-
}
561-
562549
async removeDeletedQueries() {
563550
await Promise.all(
564551
this.treeDataProvider.allHistory.map(async (item) => {
@@ -595,8 +582,6 @@ export class QueryHistoryManager extends DisposableObject {
595582
// We need to delete it from disk as well.
596583
await item.completedQuery?.query.deleteQuery();
597584
}
598-
} else if (item.t === "remote") {
599-
// Do nothing. TODO: Remove once remote queries are no longer supported.
600585
} else if (item.t === "variant-analysis") {
601586
await this.removeVariantAnalysis(item);
602587
} else {
@@ -808,8 +793,6 @@ export class QueryHistoryManager extends DisposableObject {
808793
if (queryHistoryItem.completedQuery) {
809794
return queryHistoryItem.completedQuery.query.querySaveDir;
810795
}
811-
} else if (queryHistoryItem.t === "remote") {
812-
return join(this.queryStorageDir, queryHistoryItem.queryId);
813796
} else if (queryHistoryItem.t === "variant-analysis") {
814797
return this.variantAnalysisManager.getVariantAnalysisStorageLocation(
815798
queryHistoryItem.variantAnalysis.id,
@@ -840,12 +823,6 @@ export class QueryHistoryManager extends DisposableObject {
840823
"timestamp",
841824
);
842825
}
843-
} else if (finalSingleItem.t === "remote") {
844-
externalFilePath = join(
845-
this.queryStorageDir,
846-
finalSingleItem.queryId,
847-
"timestamp",
848-
);
849826
} else if (finalSingleItem.t === "variant-analysis") {
850827
externalFilePath = join(
851828
this.variantAnalysisManager.getVariantAnalysisStorageLocation(
@@ -1012,11 +989,6 @@ export class QueryHistoryManager extends DisposableObject {
1012989
if (item.status === QueryStatus.InProgress) {
1013990
if (item.t === "local") {
1014991
item.cancel();
1015-
} else if (item.t === "remote") {
1016-
void showAndLogInformationMessage(
1017-
"Cancelling variant analysis. This may take a while.",
1018-
);
1019-
await cancelRemoteQuery(this.app.credentials, item.remoteQuery);
1020992
} else if (item.t === "variant-analysis") {
1021993
await commands.executeCommand(
1022994
"codeQL.cancelVariantAnalysis",
@@ -1239,10 +1211,8 @@ export class QueryHistoryManager extends DisposableObject {
12391211
return;
12401212
}
12411213

1242-
// Remote queries and variant analysis only
1243-
if (finalSingleItem.t === "remote") {
1244-
// Do nothing. TODO: Remove this case once remote queries are removed.
1245-
} else if (finalSingleItem.t === "variant-analysis") {
1214+
// Variant analysis only
1215+
if (finalSingleItem.t === "variant-analysis") {
12461216
await commands.executeCommand(
12471217
"codeQL.exportVariantAnalysisResults",
12481218
finalSingleItem.variantAnalysis.id,
@@ -1475,8 +1445,6 @@ the file in the file explorer and dragging it into the workspace.`,
14751445
WebviewReveal.Forced,
14761446
false,
14771447
);
1478-
} else if (item.t === "remote") {
1479-
// Do nothing. TODO: Remove when remote queries is no longer supported.
14801448
} else if (item.t === "variant-analysis") {
14811449
await this.variantAnalysisManager.showView(item.variantAnalysis.id);
14821450
} else {

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

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
} from "./pure/helpers-pure";
1111
import { CompletedQueryInfo, LocalQueryInfo } from "./query-results";
1212
import { QueryHistoryInfo } from "./query-history/query-history-info";
13-
import { QueryStatus } from "./query-status";
1413
import { QueryEvaluationInfo } from "./run-queries-shared";
1514
import { QueryResultType } from "./pure/legacy-messages";
1615
import { redactableError } from "./pure/errors";
@@ -33,58 +32,57 @@ export async function deserializeQueryHistory(
3332
}
3433

3534
const queries = obj.queries;
36-
const parsedQueries = queries.map((q: QueryHistoryInfo) => {
37-
// Need to explicitly set prototype since reading in from JSON will not
38-
// do this automatically. Note that we can't call the constructor here since
39-
// the constructor invokes extra logic that we don't want to do.
40-
if (q.t === "local") {
41-
Object.setPrototypeOf(q, LocalQueryInfo.prototype);
35+
const parsedQueries = queries
36+
// Remove remote queries, which are not supported anymore.
37+
.filter((q: QueryHistoryInfo | { t: "remote" }) => q.t !== "remote")
38+
.map((q: QueryHistoryInfo) => {
39+
// Need to explicitly set prototype since reading in from JSON will not
40+
// do this automatically. Note that we can't call the constructor here since
41+
// the constructor invokes extra logic that we don't want to do.
42+
if (q.t === "local") {
43+
Object.setPrototypeOf(q, LocalQueryInfo.prototype);
4244

43-
// Date instances are serialized as strings. Need to
44-
// convert them back to Date instances.
45-
(q.initialInfo as any).start = new Date(q.initialInfo.start);
46-
if (q.completedQuery) {
47-
// Again, need to explicitly set prototypes.
48-
Object.setPrototypeOf(q.completedQuery, CompletedQueryInfo.prototype);
49-
Object.setPrototypeOf(
50-
q.completedQuery.query,
51-
QueryEvaluationInfo.prototype,
52-
);
53-
// deserialized queries do not need to be disposed
54-
q.completedQuery.dispose = () => {
55-
/**/
56-
};
45+
// Date instances are serialized as strings. Need to
46+
// convert them back to Date instances.
47+
(q.initialInfo as any).start = new Date(q.initialInfo.start);
48+
if (q.completedQuery) {
49+
// Again, need to explicitly set prototypes.
50+
Object.setPrototypeOf(
51+
q.completedQuery,
52+
CompletedQueryInfo.prototype,
53+
);
54+
Object.setPrototypeOf(
55+
q.completedQuery.query,
56+
QueryEvaluationInfo.prototype,
57+
);
58+
// deserialized queries do not need to be disposed
59+
q.completedQuery.dispose = () => {
60+
/**/
61+
};
5762

58-
// Previously, there was a typo in the completedQuery type. There was a field
59-
// `sucessful` and it was renamed to `successful`. We need to handle this case.
60-
if ("sucessful" in q.completedQuery) {
61-
(q.completedQuery as any).successful = (
62-
q.completedQuery as any
63-
).sucessful;
64-
delete (q.completedQuery as any).sucessful;
65-
}
63+
// Previously, there was a typo in the completedQuery type. There was a field
64+
// `sucessful` and it was renamed to `successful`. We need to handle this case.
65+
if ("sucessful" in q.completedQuery) {
66+
(q.completedQuery as any).successful = (
67+
q.completedQuery as any
68+
).sucessful;
69+
delete (q.completedQuery as any).sucessful;
70+
}
6671

67-
if (!("successful" in q.completedQuery)) {
68-
(q.completedQuery as any).successful =
69-
q.completedQuery.result?.resultType === QueryResultType.SUCCESS;
72+
if (!("successful" in q.completedQuery)) {
73+
(q.completedQuery as any).successful =
74+
q.completedQuery.result?.resultType === QueryResultType.SUCCESS;
75+
}
7076
}
7177
}
72-
} else if (q.t === "remote") {
73-
// A bug was introduced that didn't set the completed flag in query history
74-
// items. The following code makes sure that the flag is set in order to
75-
// "patch" older query history items.
76-
if (q.status === QueryStatus.Completed) {
77-
q.completed = true;
78-
}
79-
}
80-
return q;
81-
});
78+
return q;
79+
});
8280

8381
// filter out queries that have been deleted on disk
8482
// most likely another workspace has deleted them because the
8583
// queries aged out.
8684
return asyncFilter(parsedQueries, async (q) => {
87-
if (q.t === "remote" || q.t === "variant-analysis") {
85+
if (q.t === "variant-analysis") {
8886
// the deserializer doesn't know where the remote queries are stored
8987
// so we need to assume here that they exist. Later, we check to
9088
// see if they exist on disk.

extensions/ql-vscode/src/remote-queries/export-results.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ export async function exportSelectedRemoteQueryResults(
4747
);
4848
}
4949

50-
if (queryHistoryItem.t === "remote") {
51-
// Do nothing. TODO: Remove this branch once we stop supporting remote queries.
52-
} else if (queryHistoryItem.t === "variant-analysis") {
50+
if (queryHistoryItem.t === "variant-analysis") {
5351
return commands.executeCommand(
5452
"codeQL.exportVariantAnalysisResults",
5553
queryHistoryItem.variantAnalysis.id,

0 commit comments

Comments
 (0)