mirror of
https://github.com/github/codeql-action.git
synced 2026-10-29 17:17:15 +00:00
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:
@@ -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,
|
||||
}),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user