fix(coding-agent): added git status cache to prevent excessive spawns

- Added 1-second TTL cache for git status to prevent excessive subprocess spawns in footer component.
This commit is contained in:
can1357
2026-01-03 19:13:22 +01:00
parent 0e7092c21c
commit f8e642adce
2 changed files with 18 additions and 1 deletions
+3
View File
@@ -1,6 +1,9 @@
# Changelog
## [Unreleased]
### Fixed
- Fixed excessive subprocess spawns by caching git status for 1 second in the footer component
## [3.3.1337] - 2026-01-03
@@ -58,6 +58,10 @@ export class FooterComponent implements Component {
private autoCompactEnabled: boolean = true;
private hookStatuses: Map<string, string> = new Map();
// Git status caching (1s TTL to avoid excessive subprocess spawns)
private cachedGitStatus: { staged: number; unstaged: number; untracked: number } | null = null;
private gitStatusLastFetch = 0;
constructor(session: AgentSession) {
this.session = session;
}
@@ -165,8 +169,14 @@ export class FooterComponent implements Component {
/**
* Get git status indicators (staged, unstaged, untracked counts).
* Returns null if not in a git repo.
* Cached for 1s to avoid excessive subprocess spawns.
*/
private getGitStatus(): { staged: number; unstaged: number; untracked: number } | null {
const now = Date.now();
if (now - this.gitStatusLastFetch < 1000) {
return this.cachedGitStatus;
}
try {
const output = execSync("git status --porcelain 2>/dev/null", {
encoding: "utf8",
@@ -200,8 +210,12 @@ export class FooterComponent implements Component {
}
}
return { staged, unstaged, untracked };
this.cachedGitStatus = { staged, unstaged, untracked };
this.gitStatusLastFetch = now;
return this.cachedGitStatus;
} catch {
this.cachedGitStatus = null;
this.gitStatusLastFetch = now;
return null;
}
}