Skip to content

Commit 8242edb

Browse files
committed
databaseRunQueries(): add optimizeForLastQueryRun parameter
1 parent 3095a09 commit 8242edb

File tree

9 files changed

+47
-11
lines changed

9 files changed

+47
-11
lines changed

lib/analyze.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ export async function runQueries(
392392
databasePath,
393393
searchPath,
394394
querySuitePath,
395-
queryFlags
395+
queryFlags,
396+
false
396397
);
397398

398399
logger.debug(`BQRS results produced for ${language} (queries: ${type})"`);
@@ -424,7 +425,8 @@ export async function runQueries(
424425
databasePath,
425426
undefined,
426427
querySuitePath,
427-
queryFlags
428+
queryFlags,
429+
false
428430
);
429431

430432
return querySuitePath;

src/codeql.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,19 @@ export interface CodeQL {
148148
): Promise<void>;
149149
/**
150150
* Run 'codeql database run-queries'.
151+
*
152+
* @param optimizeForLastQueryRun Whether to apply additional optimization for
153+
* the last database query run in the action.
154+
* It is always safe to set it to false.
155+
* It should be set to true only for the very
156+
* last databaseRunQueries() call.
151157
*/
152158
databaseRunQueries(
153159
databasePath: string,
154160
extraSearchPath: string | undefined,
155161
querySuitePath: string | undefined,
156-
flags: string[]
162+
flags: string[],
163+
optimizeForLastQueryRun: boolean
157164
): Promise<void>;
158165
/**
159166
* Run 'codeql database interpret-results'.
@@ -788,7 +795,8 @@ export async function getCodeQLForCmd(
788795
databasePath: string,
789796
extraSearchPath: string | undefined,
790797
querySuitePath: string | undefined,
791-
flags: string[]
798+
flags: string[],
799+
optimizeForLastQueryRun: boolean
792800
): Promise<void> {
793801
const codeqlArgs = [
794802
"database",
@@ -799,6 +807,12 @@ export async function getCodeQLForCmd(
799807
"-v",
800808
...getExtraOptionsFromEnv(["database", "run-queries"]),
801809
];
810+
if (
811+
optimizeForLastQueryRun &&
812+
(await util.supportExpectDiscardedCache(this))
813+
) {
814+
codeqlArgs.push("--expect-discarded-cache");
815+
}
802816
if (extraSearchPath !== undefined) {
803817
codeqlArgs.push("--additional-packs", extraSearchPath);
804818
}

src/util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,15 @@ export function isGoodVersion(versionSpec: string) {
571571
return !BROKEN_VERSIONS.includes(versionSpec);
572572
}
573573

574+
/**
575+
* Checks whether the CodeQL CLI supports the `--expect-discarded-cache` command-line flag.
576+
*/
577+
export async function supportExpectDiscardedCache(
578+
codeQL: CodeQL
579+
): Promise<boolean> {
580+
return codeQlVersionAbove(codeQL, "2.12.1");
581+
}
582+
574583
export const ML_POWERED_JS_QUERIES_PACK_NAME =
575584
"codeql/javascript-experimental-atm-queries";
576585

0 commit comments

Comments
 (0)