Front-load caching and rear-load saving to disk

This implementation saves CPU and I/O by not trying to write to the file on every set-cache.
This commit is contained in:
Mario Campos
2026-06-19 17:45:48 -05:00
parent 805b59092e
commit 895ffe7eb5
4 changed files with 40 additions and 40 deletions

13
lib/entry-points.js generated
View File

@@ -149934,9 +149934,12 @@ function readCommandCacheFile() {
}
return {};
}
function writeCommandCacheFile(data) {
function writeCommandCacheFile() {
try {
fs6.writeFileSync(getCommandCacheFilePath(), JSON.stringify(data));
fs6.writeFileSync(
getCommandCacheFilePath(),
JSON.stringify(Object.fromEntries(inMemoryCache))
);
} catch (e) {
logger.warning(`Failed to write command cache file: ${e}`);
}
@@ -149944,9 +149947,6 @@ function writeCommandCacheFile(data) {
function cacheCommandOutput(key, cmd, output) {
const entry = { cmd, output };
inMemoryCache.set(key, entry);
const data = readCommandCacheFile();
data[key] = entry;
writeCommandCacheFile(data);
}
function getCachedCommandOutput(key, cmd, validate) {
const memoized = inMemoryCache.get(key);
@@ -159013,6 +159013,8 @@ async function run3(startedAt) {
toolsVersion = initCodeQLResult.toolsVersion;
toolsSource = initCodeQLResult.toolsSource;
zstdAvailability = initCodeQLResult.zstdAvailability;
await codeql.getVersion();
await codeql.resolveLanguages();
await checkWorkflow(logger2, codeql);
if (
// Only enable the experimental features env variable for Rust analysis if the user has explicitly
@@ -159322,6 +159324,7 @@ exec ${goBinaryPath} "$@"`
await saveConfig(config, logger2);
core20.setOutput("codeql-path", config.codeQLCmd);
core20.setOutput("codeql-version", (await codeql.getVersion()).version);
writeCommandCacheFile();
} catch (unwrappedError) {
const error3 = wrapError(unwrappedError);
core20.setFailed(error3.message);