perf(extension): parallelize async operations and cache checks
This commit is contained in:
@@ -6,6 +6,8 @@ export interface GenerateOptions {
|
||||
model?: string;
|
||||
}
|
||||
|
||||
let opencodeAvailableCache: boolean | null = null;
|
||||
|
||||
const DEFAULT_PROMPT = `You are a helpful assistant that generates git commit messages.
|
||||
Generate a concise Conventional Commit message (max 72 characters for the subject line).
|
||||
Format: <type>(<scope>): <description>
|
||||
@@ -15,9 +17,13 @@ Types: feat, fix, refactor, docs, style, test, chore, perf, ci, build, revert
|
||||
Only output the commit message, nothing else.`;
|
||||
|
||||
export async function isOpenCodeAvailable(): Promise<boolean> {
|
||||
if (opencodeAvailableCache !== null) {
|
||||
return opencodeAvailableCache;
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
exec("which opencode", (error: ExecException | null) => {
|
||||
resolve(!error);
|
||||
opencodeAvailableCache = !error;
|
||||
resolve(opencodeAvailableCache);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -32,8 +38,10 @@ export async function generateCommitMessage(
|
||||
);
|
||||
}
|
||||
|
||||
const diff = await getGitDiff();
|
||||
const repoRoot = await getRepositoryRoot();
|
||||
const [diff, repoRoot] = await Promise.all([
|
||||
getGitDiff(),
|
||||
getRepositoryRoot(),
|
||||
]);
|
||||
|
||||
const config = vscode.workspace.getConfiguration("aiCommitExt");
|
||||
const model = options.model || config.get<string>("model", "");
|
||||
|
||||
Reference in New Issue
Block a user