Skip to content

Commit 2741889

Browse files
committed
Cache common result set names
This caches the common result set names and moves the common result set names from the `SetComparisonsMessage` to the `SetComparisonQueryInfoMessage`.
1 parent 3554bce commit 2741889

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

extensions/ql-vscode/src/common/interface-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,14 @@ export interface SetComparisonQueryInfoMessage {
356356
};
357357
};
358358
readonly databaseUri: string;
359+
readonly commonResultSetNames: string[];
359360
}
360361

361362
/**
362363
* Message to the compare view that specifies the query results to compare.
363364
*/
364365
export interface SetComparisonsMessage {
365366
readonly t: "setComparisons";
366-
readonly commonResultSetNames: string[];
367367
readonly currentResultSetName: string;
368368
readonly result: RawQueryCompareResult | undefined;
369369
readonly message: string | undefined;

extensions/ql-vscode/src/compare/compare-view.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ import {
2222
import { telemetryListener } from "../common/vscode/telemetry";
2323
import { redactableError } from "../common/errors";
2424
import { App } from "../common/app";
25-
import { findResultSetNames } from "./result-set-names";
25+
import {
26+
findCommonResultSetNames,
27+
findResultSetNames,
28+
} from "./result-set-names";
2629

2730
interface ComparePair {
2831
from: CompletedLocalQueryInfo;
2932
fromSchemas: BQRSInfo;
3033
to: CompletedLocalQueryInfo;
3134
toSchemas: BQRSInfo;
35+
36+
commonResultSetNames: readonly string[];
3237
}
3338

3439
export class CompareView extends AbstractWebview<
@@ -62,11 +67,17 @@ export class CompareView extends AbstractWebview<
6267
to.completedQuery.query.resultsPaths.resultsPath,
6368
);
6469

70+
const commonResultSetNames = await findCommonResultSetNames(
71+
fromSchemas,
72+
toSchemas,
73+
);
74+
6575
this.comparePair = {
6676
from,
6777
fromSchemas,
6878
to,
6979
toSchemas,
80+
commonResultSetNames,
7081
};
7182

7283
await this.postMessage({
@@ -87,6 +98,7 @@ export class CompareView extends AbstractWebview<
8798
},
8899
},
89100
databaseUri: to.initialInfo.databaseInfo.databaseUri,
101+
commonResultSetNames,
90102
});
91103

92104
await this.showResultsInternal(selectedResultSetName);
@@ -101,15 +113,11 @@ export class CompareView extends AbstractWebview<
101113
panel.reveal(undefined, true);
102114

103115
await this.waitForPanelLoaded();
104-
const {
105-
commonResultSetNames,
106-
currentResultSetDisplayName,
107-
fromResultSet,
108-
toResultSet,
109-
} = await this.findResultSetsToCompare(
110-
this.comparePair,
111-
selectedResultSetName,
112-
);
116+
const { currentResultSetDisplayName, fromResultSet, toResultSet } =
117+
await this.findResultSetsToCompare(
118+
this.comparePair,
119+
selectedResultSetName,
120+
);
113121
if (currentResultSetDisplayName) {
114122
let result: RawQueryCompareResult | undefined;
115123
let message: string | undefined;
@@ -122,7 +130,6 @@ export class CompareView extends AbstractWebview<
122130
await this.postMessage({
123131
t: "setComparisons",
124132
result,
125-
commonResultSetNames,
126133
currentResultSetName: currentResultSetDisplayName,
127134
message,
128135
});
@@ -192,15 +199,16 @@ export class CompareView extends AbstractWebview<
192199
}
193200

194201
private async findResultSetsToCompare(
195-
{ from, fromSchemas, to, toSchemas }: ComparePair,
202+
{ from, fromSchemas, to, toSchemas, commonResultSetNames }: ComparePair,
196203
selectedResultSetName: string | undefined,
197204
) {
198-
const {
199-
commonResultSetNames,
200-
currentResultSetDisplayName,
201-
fromResultSetName,
202-
toResultSetName,
203-
} = await findResultSetNames(fromSchemas, toSchemas, selectedResultSetName);
205+
const { currentResultSetDisplayName, fromResultSetName, toResultSetName } =
206+
await findResultSetNames(
207+
fromSchemas,
208+
toSchemas,
209+
commonResultSetNames,
210+
selectedResultSetName,
211+
);
204212

205213
const fromResultSet = await this.getResultSet(
206214
fromSchemas,
@@ -213,7 +221,6 @@ export class CompareView extends AbstractWebview<
213221
to.completedQuery.query.resultsPaths.resultsPath,
214222
);
215223
return {
216-
commonResultSetNames,
217224
currentResultSetDisplayName,
218225
fromResultSet,
219226
toResultSet,

extensions/ql-vscode/src/compare/result-set-names.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import { BQRSInfo } from "../common/bqrs-cli-types";
22

3+
export async function findCommonResultSetNames(
4+
fromSchemas: BQRSInfo,
5+
toSchemas: BQRSInfo,
6+
): Promise<string[]> {
7+
const fromSchemaNames = fromSchemas["result-sets"].map(
8+
(schema) => schema.name,
9+
);
10+
const toSchemaNames = toSchemas["result-sets"].map((schema) => schema.name);
11+
12+
return fromSchemaNames.filter((name) => toSchemaNames.includes(name));
13+
}
14+
315
export async function findResultSetNames(
416
fromSchemas: BQRSInfo,
517
toSchemas: BQRSInfo,
18+
commonResultSetNames: readonly string[],
619
selectedResultSetName: string | undefined,
720
) {
821
const fromSchemaNames = fromSchemas["result-sets"].map(
922
(schema) => schema.name,
1023
);
1124
const toSchemaNames = toSchemas["result-sets"].map((schema) => schema.name);
12-
const commonResultSetNames = fromSchemaNames.filter((name) =>
13-
toSchemaNames.includes(name),
14-
);
1525

1626
// Fall back on the default result set names if there are no common ones.
1727
const defaultFromResultSetName = fromSchemaNames.find((name) =>
@@ -35,7 +45,6 @@ export async function findResultSetNames(
3545
const toResultSetName = currentResultSetName || defaultToResultSetName!;
3646

3747
return {
38-
commonResultSetNames,
3948
currentResultSetDisplayName:
4049
currentResultSetName ||
4150
`${defaultFromResultSetName} <-> ${defaultToResultSetName}`,

extensions/ql-vscode/src/stories/compare/CompareTable.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ CompareTable.args = {
3232
},
3333
},
3434
databaseUri: "file:///java",
35+
commonResultSetNames: ["edges", "nodes", "subpaths", "#select"],
3536
},
3637
comparison: {
3738
t: "setComparisons",
38-
commonResultSetNames: ["edges", "nodes", "subpaths", "#select"],
3939
currentResultSetName: "edges",
4040
result: {
4141
columns: [

extensions/ql-vscode/src/view/compare/Compare.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function Compare(_: Record<string, never>): JSX.Element {
7575
<Header>
7676
<HeaderTitle>Comparing:</HeaderTitle>
7777
<CompareSelector
78-
availableResultSets={comparison.commonResultSetNames}
78+
availableResultSets={queryInfo.commonResultSetNames}
7979
currentResultSetName={comparison.currentResultSetName}
8080
updateResultSet={(newResultSetName: string) =>
8181
vscode.postMessage({ t: "changeCompare", newResultSetName })

0 commit comments

Comments
 (0)