Calculate customQueryIndices early
This refactoring commit changes runQueries() to calculate the set of indices with non-empty custom queries early. Doing so allows us to check early on whether there are any custom queries to run.
This commit is contained in:
parent
8242edb8ed
commit
08d1f21d4f
3 changed files with 31 additions and 25 deletions
18
lib/analyze.js
generated
18
lib/analyze.js
generated
|
|
@ -165,21 +165,25 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
||||||
!hasPackWithCustomQueries) {
|
!hasPackWithCustomQueries) {
|
||||||
throw new Error(`Unable to analyze ${language} as no queries were selected for this language`);
|
throw new Error(`Unable to analyze ${language} as no queries were selected for this language`);
|
||||||
}
|
}
|
||||||
|
const customQueryIndices = [];
|
||||||
|
for (let i = 0; i < queries.custom.length; ++i) {
|
||||||
|
if (queries.custom[i].queries.length > 0) {
|
||||||
|
customQueryIndices.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
logger.startGroup(`Running queries for ${language}`);
|
logger.startGroup(`Running queries for ${language}`);
|
||||||
const querySuitePaths = [];
|
const querySuitePaths = [];
|
||||||
if (queries["builtin"].length > 0) {
|
if (queries.builtin.length > 0) {
|
||||||
const startTimeBuiltIn = new Date().getTime();
|
const startTimeBuiltIn = new Date().getTime();
|
||||||
querySuitePaths.push((await runQueryGroup(language, "builtin", createQuerySuiteContents(queries["builtin"], queryFilters), undefined)));
|
querySuitePaths.push((await runQueryGroup(language, "builtin", createQuerySuiteContents(queries.builtin, queryFilters), undefined)));
|
||||||
statusReport[`analyze_builtin_queries_${language}_duration_ms`] =
|
statusReport[`analyze_builtin_queries_${language}_duration_ms`] =
|
||||||
new Date().getTime() - startTimeBuiltIn;
|
new Date().getTime() - startTimeBuiltIn;
|
||||||
}
|
}
|
||||||
const startTimeCustom = new Date().getTime();
|
const startTimeCustom = new Date().getTime();
|
||||||
let ranCustom = false;
|
let ranCustom = false;
|
||||||
for (let i = 0; i < queries["custom"].length; ++i) {
|
for (const i of customQueryIndices) {
|
||||||
if (queries["custom"][i].queries.length > 0) {
|
querySuitePaths.push((await runQueryGroup(language, `custom-${i}`, createQuerySuiteContents(queries.custom[i].queries, queryFilters), queries.custom[i].searchPath)));
|
||||||
querySuitePaths.push((await runQueryGroup(language, `custom-${i}`, createQuerySuiteContents(queries["custom"][i].queries, queryFilters), queries["custom"][i].searchPath)));
|
ranCustom = true;
|
||||||
ranCustom = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (packsWithVersion.length > 0) {
|
if (packsWithVersion.length > 0) {
|
||||||
querySuitePaths.push(await runQueryPacks(language, "packs", packsWithVersion, queryFilters));
|
querySuitePaths.push(await runQueryPacks(language, "packs", packsWithVersion, queryFilters));
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -268,15 +268,22 @@ export async function runQueries(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const customQueryIndices: number[] = [];
|
||||||
|
for (let i = 0; i < queries.custom.length; ++i) {
|
||||||
|
if (queries.custom[i].queries.length > 0) {
|
||||||
|
customQueryIndices.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.startGroup(`Running queries for ${language}`);
|
logger.startGroup(`Running queries for ${language}`);
|
||||||
const querySuitePaths: string[] = [];
|
const querySuitePaths: string[] = [];
|
||||||
if (queries["builtin"].length > 0) {
|
if (queries.builtin.length > 0) {
|
||||||
const startTimeBuiltIn = new Date().getTime();
|
const startTimeBuiltIn = new Date().getTime();
|
||||||
querySuitePaths.push(
|
querySuitePaths.push(
|
||||||
(await runQueryGroup(
|
(await runQueryGroup(
|
||||||
language,
|
language,
|
||||||
"builtin",
|
"builtin",
|
||||||
createQuerySuiteContents(queries["builtin"], queryFilters),
|
createQuerySuiteContents(queries.builtin, queryFilters),
|
||||||
undefined
|
undefined
|
||||||
)) as string
|
)) as string
|
||||||
);
|
);
|
||||||
|
|
@ -285,21 +292,16 @@ export async function runQueries(
|
||||||
}
|
}
|
||||||
const startTimeCustom = new Date().getTime();
|
const startTimeCustom = new Date().getTime();
|
||||||
let ranCustom = false;
|
let ranCustom = false;
|
||||||
for (let i = 0; i < queries["custom"].length; ++i) {
|
for (const i of customQueryIndices) {
|
||||||
if (queries["custom"][i].queries.length > 0) {
|
querySuitePaths.push(
|
||||||
querySuitePaths.push(
|
(await runQueryGroup(
|
||||||
(await runQueryGroup(
|
language,
|
||||||
language,
|
`custom-${i}`,
|
||||||
`custom-${i}`,
|
createQuerySuiteContents(queries.custom[i].queries, queryFilters),
|
||||||
createQuerySuiteContents(
|
queries.custom[i].searchPath
|
||||||
queries["custom"][i].queries,
|
)) as string
|
||||||
queryFilters
|
);
|
||||||
),
|
ranCustom = true;
|
||||||
queries["custom"][i].searchPath
|
|
||||||
)) as string
|
|
||||||
);
|
|
||||||
ranCustom = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (packsWithVersion.length > 0) {
|
if (packsWithVersion.length > 0) {
|
||||||
querySuitePaths.push(
|
querySuitePaths.push(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue