Skip to content

Commit

Permalink
Improve performance of compare view using Promise.all
Browse files Browse the repository at this point in the history
  • Loading branch information
koesie10 committed Dec 6, 2023
1 parent 0ab4bff commit fc9430d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
34 changes: 18 additions & 16 deletions extensions/ql-vscode/src/compare/compare-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ export class CompareView extends AbstractWebview<
to: CompletedLocalQueryInfo,
selectedResultSetName?: string,
) {
const fromSchemas = await this.cliServer.bqrsInfo(
from.completedQuery.query.resultsPaths.resultsPath,
);
const toSchemas = await this.cliServer.bqrsInfo(
to.completedQuery.query.resultsPaths.resultsPath,
);
const [fromSchemas, toSchemas] = await Promise.all([
this.cliServer.bqrsInfo(
from.completedQuery.query.resultsPaths.resultsPath,
),
this.cliServer.bqrsInfo(to.completedQuery.query.resultsPaths.resultsPath),
]);

this.comparePair = {
from,
Expand Down Expand Up @@ -256,16 +256,18 @@ export class CompareView extends AbstractWebview<
fromResultSetName: string,
toResultSetName: string,
): Promise<RawQueryCompareResult> {
const fromResultSet = await this.getResultSet(
fromInfo.schemas,
fromResultSetName,
from.completedQuery.query.resultsPaths.resultsPath,
);
const toResultSet = await this.getResultSet(
toInfo.schemas,
toResultSetName,
to.completedQuery.query.resultsPaths.resultsPath,
);
const [fromResultSet, toResultSet] = await Promise.all([
this.getResultSet(
fromInfo.schemas,
fromResultSetName,
from.completedQuery.query.resultsPaths.resultsPath,
),
this.getResultSet(
toInfo.schemas,
toResultSetName,
to.completedQuery.query.resultsPaths.resultsPath,
),
]);

// Only compare columns that have the same name
return resultsDiff(fromResultSet, toResultSet);
Expand Down
32 changes: 15 additions & 17 deletions extensions/ql-vscode/src/compare/interpreted-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ export async function compareInterpretedResults(
fromQuery: CompletedLocalQueryInfo,
toQuery: CompletedLocalQueryInfo,
): Promise<InterpretedQueryCompareResult> {
const fromResultSet = await getInterpretedResults(
fromQuery.completedQuery.query.resultsPaths.interpretedResultsPath,
);

const toResultSet = await getInterpretedResults(
toQuery.completedQuery.query.resultsPaths.interpretedResultsPath,
);

if (!fromResultSet || !toResultSet) {
throw new Error(
"Could not find interpreted results for one or both queries.",
);
}

const database = databaseManager.findDatabaseItem(
Uri.parse(toQuery.initialInfo.databaseInfo.databaseUri),
);
Expand All @@ -48,9 +34,21 @@ export async function compareInterpretedResults(
);
}

const sourceLocationPrefix = await database.getSourceLocationPrefix(
cliServer,
);
const [fromResultSet, toResultSet, sourceLocationPrefix] = await Promise.all([
getInterpretedResults(
fromQuery.completedQuery.query.resultsPaths.interpretedResultsPath,
),
getInterpretedResults(
toQuery.completedQuery.query.resultsPaths.interpretedResultsPath,
),
database.getSourceLocationPrefix(cliServer),
]);

if (!fromResultSet || !toResultSet) {
throw new Error(
"Could not find interpreted results for one or both queries.",
);
}

const fromResults = fromResultSet.runs[0].results;
const toResults = toResultSet.runs[0].results;
Expand Down

0 comments on commit fc9430d

Please sign in to comment.