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`.
This commit is contained in:
@@ -356,6 +356,7 @@ export interface SetComparisonQueryInfoMessage {
|
||||
};
|
||||
};
|
||||
readonly databaseUri: string;
|
||||
readonly commonResultSetNames: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,7 +364,6 @@ export interface SetComparisonQueryInfoMessage {
|
||||
*/
|
||||
export interface SetComparisonsMessage {
|
||||
readonly t: "setComparisons";
|
||||
readonly commonResultSetNames: string[];
|
||||
readonly currentResultSetName: string;
|
||||
readonly result: RawQueryCompareResult | undefined;
|
||||
readonly message: string | undefined;
|
||||
|
||||
@@ -22,13 +22,18 @@ import {
|
||||
import { telemetryListener } from "../common/vscode/telemetry";
|
||||
import { redactableError } from "../common/errors";
|
||||
import { App } from "../common/app";
|
||||
import { findResultSetNames } from "./result-set-names";
|
||||
import {
|
||||
findCommonResultSetNames,
|
||||
findResultSetNames,
|
||||
} from "./result-set-names";
|
||||
|
||||
interface ComparePair {
|
||||
from: CompletedLocalQueryInfo;
|
||||
fromSchemas: BQRSInfo;
|
||||
to: CompletedLocalQueryInfo;
|
||||
toSchemas: BQRSInfo;
|
||||
|
||||
commonResultSetNames: readonly string[];
|
||||
}
|
||||
|
||||
export class CompareView extends AbstractWebview<
|
||||
@@ -62,11 +67,17 @@ export class CompareView extends AbstractWebview<
|
||||
to.completedQuery.query.resultsPaths.resultsPath,
|
||||
);
|
||||
|
||||
const commonResultSetNames = await findCommonResultSetNames(
|
||||
fromSchemas,
|
||||
toSchemas,
|
||||
);
|
||||
|
||||
this.comparePair = {
|
||||
from,
|
||||
fromSchemas,
|
||||
to,
|
||||
toSchemas,
|
||||
commonResultSetNames,
|
||||
};
|
||||
|
||||
await this.postMessage({
|
||||
@@ -87,6 +98,7 @@ export class CompareView extends AbstractWebview<
|
||||
},
|
||||
},
|
||||
databaseUri: to.initialInfo.databaseInfo.databaseUri,
|
||||
commonResultSetNames,
|
||||
});
|
||||
|
||||
await this.showResultsInternal(selectedResultSetName);
|
||||
@@ -101,15 +113,11 @@ export class CompareView extends AbstractWebview<
|
||||
panel.reveal(undefined, true);
|
||||
|
||||
await this.waitForPanelLoaded();
|
||||
const {
|
||||
commonResultSetNames,
|
||||
currentResultSetDisplayName,
|
||||
fromResultSet,
|
||||
toResultSet,
|
||||
} = await this.findResultSetsToCompare(
|
||||
this.comparePair,
|
||||
selectedResultSetName,
|
||||
);
|
||||
const { currentResultSetDisplayName, fromResultSet, toResultSet } =
|
||||
await this.findResultSetsToCompare(
|
||||
this.comparePair,
|
||||
selectedResultSetName,
|
||||
);
|
||||
if (currentResultSetDisplayName) {
|
||||
let result: RawQueryCompareResult | undefined;
|
||||
let message: string | undefined;
|
||||
@@ -122,7 +130,6 @@ export class CompareView extends AbstractWebview<
|
||||
await this.postMessage({
|
||||
t: "setComparisons",
|
||||
result,
|
||||
commonResultSetNames,
|
||||
currentResultSetName: currentResultSetDisplayName,
|
||||
message,
|
||||
});
|
||||
@@ -192,15 +199,16 @@ export class CompareView extends AbstractWebview<
|
||||
}
|
||||
|
||||
private async findResultSetsToCompare(
|
||||
{ from, fromSchemas, to, toSchemas }: ComparePair,
|
||||
{ from, fromSchemas, to, toSchemas, commonResultSetNames }: ComparePair,
|
||||
selectedResultSetName: string | undefined,
|
||||
) {
|
||||
const {
|
||||
commonResultSetNames,
|
||||
currentResultSetDisplayName,
|
||||
fromResultSetName,
|
||||
toResultSetName,
|
||||
} = await findResultSetNames(fromSchemas, toSchemas, selectedResultSetName);
|
||||
const { currentResultSetDisplayName, fromResultSetName, toResultSetName } =
|
||||
await findResultSetNames(
|
||||
fromSchemas,
|
||||
toSchemas,
|
||||
commonResultSetNames,
|
||||
selectedResultSetName,
|
||||
);
|
||||
|
||||
const fromResultSet = await this.getResultSet(
|
||||
fromSchemas,
|
||||
@@ -213,7 +221,6 @@ export class CompareView extends AbstractWebview<
|
||||
to.completedQuery.query.resultsPaths.resultsPath,
|
||||
);
|
||||
return {
|
||||
commonResultSetNames,
|
||||
currentResultSetDisplayName,
|
||||
fromResultSet,
|
||||
toResultSet,
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
import { BQRSInfo } from "../common/bqrs-cli-types";
|
||||
|
||||
export async function findCommonResultSetNames(
|
||||
fromSchemas: BQRSInfo,
|
||||
toSchemas: BQRSInfo,
|
||||
): Promise<string[]> {
|
||||
const fromSchemaNames = fromSchemas["result-sets"].map(
|
||||
(schema) => schema.name,
|
||||
);
|
||||
const toSchemaNames = toSchemas["result-sets"].map((schema) => schema.name);
|
||||
|
||||
return fromSchemaNames.filter((name) => toSchemaNames.includes(name));
|
||||
}
|
||||
|
||||
export async function findResultSetNames(
|
||||
fromSchemas: BQRSInfo,
|
||||
toSchemas: BQRSInfo,
|
||||
commonResultSetNames: readonly string[],
|
||||
selectedResultSetName: string | undefined,
|
||||
) {
|
||||
const fromSchemaNames = fromSchemas["result-sets"].map(
|
||||
(schema) => schema.name,
|
||||
);
|
||||
const toSchemaNames = toSchemas["result-sets"].map((schema) => schema.name);
|
||||
const commonResultSetNames = fromSchemaNames.filter((name) =>
|
||||
toSchemaNames.includes(name),
|
||||
);
|
||||
|
||||
// Fall back on the default result set names if there are no common ones.
|
||||
const defaultFromResultSetName = fromSchemaNames.find((name) =>
|
||||
@@ -35,7 +45,6 @@ export async function findResultSetNames(
|
||||
const toResultSetName = currentResultSetName || defaultToResultSetName!;
|
||||
|
||||
return {
|
||||
commonResultSetNames,
|
||||
currentResultSetDisplayName:
|
||||
currentResultSetName ||
|
||||
`${defaultFromResultSetName} <-> ${defaultToResultSetName}`,
|
||||
|
||||
@@ -32,10 +32,10 @@ CompareTable.args = {
|
||||
},
|
||||
},
|
||||
databaseUri: "file:///java",
|
||||
commonResultSetNames: ["edges", "nodes", "subpaths", "#select"],
|
||||
},
|
||||
comparison: {
|
||||
t: "setComparisons",
|
||||
commonResultSetNames: ["edges", "nodes", "subpaths", "#select"],
|
||||
currentResultSetName: "edges",
|
||||
result: {
|
||||
columns: [
|
||||
|
||||
@@ -75,7 +75,7 @@ export function Compare(_: Record<string, never>): JSX.Element {
|
||||
<Header>
|
||||
<HeaderTitle>Comparing:</HeaderTitle>
|
||||
<CompareSelector
|
||||
availableResultSets={comparison.commonResultSetNames}
|
||||
availableResultSets={queryInfo.commonResultSetNames}
|
||||
currentResultSetName={comparison.currentResultSetName}
|
||||
updateResultSet={(newResultSetName: string) =>
|
||||
vscode.postMessage({ t: "changeCompare", newResultSetName })
|
||||
|
||||
Reference in New Issue
Block a user