perf: reduce renderer and repository polling work
ForgeFlow quality gate / quality (push) Canceled after 0s

This commit is contained in:
NuklearRabbit
2026-08-01 14:24:53 +02:00
parent 258f0b1324
commit 13f4fe7cd0
5 changed files with 105 additions and 61 deletions
+24 -19
View File
@@ -40,27 +40,32 @@ class RepositoryMonitor {
if (this.running || !this.paths.length) return;
this.running = true;
try {
for (const localPath of this.paths) {
if (this.paused.has(localPath)) continue;
try {
const status = await this.git.status(localPath);
const next = this.git.statusFingerprint(status);
const previous = this.fingerprints.get(localPath);
this.fingerprints.set(localPath, next);
if (previous && previous !== next) {
await this.diagnostics?.debug('repository-monitor.changed', { localPath, head: status.head, branch: status.branch?.head, counts: status.counts });
this.onChange?.({ localPath, status, reason: 'working-tree-changed' });
}
} catch (error) {
const next = `error:${error.message}`;
const previous = this.fingerprints.get(localPath);
this.fingerprints.set(localPath, next);
if (previous && previous !== next) {
await this.diagnostics?.warning('repository-monitor.unavailable', { localPath, message: error.message });
this.onChange?.({ localPath, error: error.message, reason: 'repository-unavailable' });
const queue = [...this.paths];
const workers = Array.from({ length: Math.min(4, queue.length) }, async () => {
while (queue.length) {
const localPath = queue.shift();
if (this.paused.has(localPath)) continue;
try {
const status = await this.git.status(localPath);
const next = this.git.statusFingerprint(status);
const previous = this.fingerprints.get(localPath);
this.fingerprints.set(localPath, next);
if (previous && previous !== next) {
await this.diagnostics?.debug('repository-monitor.changed', { localPath, head: status.head, branch: status.branch?.head, counts: status.counts });
this.onChange?.({ localPath, status, reason: 'working-tree-changed' });
}
} catch (error) {
const next = `error:${error.message}`;
const previous = this.fingerprints.get(localPath);
this.fingerprints.set(localPath, next);
if (previous && previous !== next) {
await this.diagnostics?.warning('repository-monitor.unavailable', { localPath, message: error.message });
this.onChange?.({ localPath, error: error.message, reason: 'repository-unavailable' });
}
}
}
}
});
await Promise.all(workers);
} finally {
this.running = false;
}