Skip to content

Commit 5634a8e

Browse files
centdixclaude
andcommitted
perf: reduce GitHub API usage by scoping PR polls to active worktrees
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6d2bbf4 commit 5634a8e

3 files changed

Lines changed: 40 additions & 16 deletions

File tree

backend/src/pr.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,14 @@ export async function syncPrStatus(
428428
}
429429
}
430430

431-
// Fetch inline review comments for open PRs whose updatedAt has changed.
431+
const wtPaths = await getWorktreePaths();
432+
const activeBranches = new Set(wtPaths.keys());
433+
434+
// Fetch inline review comments only for PRs matching active worktrees.
432435
// PRs that haven't been updated reuse cached comments (saves API calls).
433436
const reviewTuples: { entry: PrEntry; repoSlug: string | undefined }[] = [];
434-
for (const entries of branchPrs.values()) {
437+
for (const [branch, entries] of branchPrs) {
438+
if (!activeBranches.has(branch)) continue;
435439
for (const entry of entries) {
436440
if (entry.state !== "open") continue;
437441
const cachedUpdatedAt = prUpdatedAtCache.get(entry.url);
@@ -464,8 +468,6 @@ export async function syncPrStatus(
464468
);
465469
}
466470
}
467-
468-
const wtPaths = await getWorktreePaths();
469471
const seen = new Set<string>();
470472

471473
for (const [branch, entries] of branchPrs) {

bin/src/init.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ function checkDeps(): Dep[] {
2727
for (const dep of deps) {
2828
const found = which(dep.tool);
2929
if (found) {
30-
p.log.success(`${dep.tool} — found`);
30+
console.log(` ✓ ${dep.tool}`);
3131
} else if (dep.required) {
32-
p.log.error(`${dep.tool} — not found (required)`);
32+
console.log(` ✗ ${dep.tool} — not found (required)`);
3333
missing.push(dep);
3434
} else {
35-
p.log.warning(`${dep.tool} — not found (optional: ${dep.hint})`);
35+
console.log(` ○ ${dep.tool} — not found (optional)`);
3636
}
3737
}
3838
return missing;
@@ -144,11 +144,9 @@ if (existsSync(wmdevYaml)) {
144144
}
145145

146146
// Step 6 — Summary
147-
p.note(
148-
`1. Edit .workmux.yaml to configure pane layout for your project
149-
2. Edit .wmdev.yaml to set up service ports and profiles
150-
3. Run: wmdev`,
151-
"Next steps",
152-
);
153-
154-
p.outro("You're all set!");
147+
p.outro("You're all set! Next steps:");
148+
console.log();
149+
console.log(" 1. Edit .workmux.yaml to configure pane layout for your project");
150+
console.log(" 2. Edit .wmdev.yaml to set up service ports and profiles");
151+
console.log(" 3. Run: wmdev");
152+
console.log();

frontend/src/App.svelte

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,32 @@
288288
Notification.requestPermission().catch(() => {});
289289
}
290290
291-
// Pause polling when tab is hidden to reduce server load.
291+
// Pause polling when tab is hidden or idle (no interaction for 60s).
292+
let idleTimer: ReturnType<typeof setTimeout>;
293+
let idle = false;
294+
295+
function resetIdleTimer(): void {
296+
if (idle) {
297+
idle = false;
298+
refresh();
299+
interval = setInterval(refresh, 5000);
300+
}
301+
clearTimeout(idleTimer);
302+
idleTimer = setTimeout(() => {
303+
idle = true;
304+
clearInterval(interval);
305+
}, 60_000);
306+
}
307+
308+
document.addEventListener("click", resetIdleTimer);
309+
document.addEventListener("keydown", resetIdleTimer);
310+
resetIdleTimer();
311+
292312
function onVisibilityChange(): void {
293313
if (document.hidden) {
294314
clearInterval(interval);
295315
} else {
316+
resetIdleTimer();
296317
refresh();
297318
interval = setInterval(refresh, 5000);
298319
}
@@ -309,6 +330,9 @@
309330
310331
return () => {
311332
clearInterval(interval);
333+
clearTimeout(idleTimer);
334+
document.removeEventListener("click", resetIdleTimer);
335+
document.removeEventListener("keydown", resetIdleTimer);
312336
window.removeEventListener("keydown", handleKeydown);
313337
document.removeEventListener("visibilitychange", onVisibilityChange);
314338
mq.removeEventListener("change", onMqChange);

0 commit comments

Comments
 (0)