mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-05 07:10:55 +00:00
perf: add cache for commandExists to fix CI timeout
- Add commandExistsCache Map to avoid repeated execSync calls - Cache command existence check results to improve test performance - Fix CI test timeout issue (was timing out after 7m) The commandExists() function was being called frequently during tests, causing slow test execution due to repeated system command calls. By caching the results, we significantly improve performance in test environments while maintaining the same functionality.
This commit is contained in:
parent
e30c2dbe23
commit
48bc0f35d7
1 changed files with 12 additions and 0 deletions
|
|
@ -29,17 +29,29 @@ const editorCommands: Record<
|
|||
trae: { win32: ['trae'], default: ['trae'] },
|
||||
};
|
||||
|
||||
/**
|
||||
* Cache for command existence checks to avoid repeated execSync calls.
|
||||
*/
|
||||
const commandExistsCache = new Map<string, boolean>();
|
||||
|
||||
/**
|
||||
* Check if a command exists in the system.
|
||||
* Results are cached to improve performance in test environments.
|
||||
*/
|
||||
function commandExists(cmd: string): boolean {
|
||||
if (commandExistsCache.has(cmd)) {
|
||||
return commandExistsCache.get(cmd)!;
|
||||
}
|
||||
|
||||
try {
|
||||
execSync(
|
||||
process.platform === 'win32' ? `where.exe ${cmd}` : `command -v ${cmd}`,
|
||||
{ stdio: 'ignore' },
|
||||
);
|
||||
commandExistsCache.set(cmd, true);
|
||||
return true;
|
||||
} catch {
|
||||
commandExistsCache.set(cmd, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue