Remove duplicate key check in cacheCommandOutput and related tests

This key-check is unnecessary because this function is only ever called if the key does NOT exist in the cache already. In that case, why check again?
This commit is contained in:
Mario Campos
2026-06-19 16:29:52 -05:00
parent d1bd5ec7b0
commit 805b59092e
3 changed files with 0 additions and 30 deletions

5
lib/entry-points.js generated
View File

@@ -149942,11 +149942,6 @@ function writeCommandCacheFile(data) {
}
}
function cacheCommandOutput(key, cmd, output) {
if (inMemoryCache.has(key)) {
throw new Error(
`cacheCommandOutput() should be called only once per key, but was called more than once for '${key}'.`
);
}
const entry = { cmd, output };
inMemoryCache.set(key, entry);
const data = readCommandCacheFile();

View File

@@ -216,19 +216,3 @@ test.serial(
});
},
);
test.serial(
"cacheCommandOutput throws if called twice for the same key",
async (t) => {
await withCacheDir(() => {
cacheCommandOutput(CommandCacheKey.Version, "/path/to/codeql", {
value: 1,
});
t.throws(() =>
cacheCommandOutput(CommandCacheKey.Version, "/path/to/codeql", {
value: 2,
}),
);
});
},
);

View File

@@ -79,21 +79,12 @@ function writeCommandCacheFile(data: Record<string, CommandCacheEntry>): void {
/**
* Stores the output of a command under `key`, writing it to both the in-memory
* memo (tier 1) and the temporary file (tier 2).
*
* Should only be called once per key within a single process; doing otherwise
* indicates a logic error, since a value that has already been cached should be
* served from the memo rather than recomputed.
*/
export function cacheCommandOutput(
key: CommandCacheKey,
cmd: string,
output: unknown,
): void {
if (inMemoryCache.has(key)) {
throw new Error(
`cacheCommandOutput() should be called only once per key, but was called more than once for '${key}'.`,
);
}
const entry: CommandCacheEntry = { cmd, output };
inMemoryCache.set(key, entry);