Skip to content

Commit ebb9c0d

Browse files
matt2eclaude
andauthored
perf(staged): move PR polling to a backend scheduler and coalesce status events (#783)
Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2ee94cb commit ebb9c0d

9 files changed

Lines changed: 1509 additions & 320 deletions

File tree

apps/staged/src-tauri/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub mod image_commands;
1717
pub mod migrations;
1818
pub mod note_commands;
1919
pub mod paths;
20+
pub mod pr_poll_scheduler;
2021
pub mod project_commands;
2122
pub mod project_mcp;
2223
pub mod prs;
@@ -2002,6 +2003,11 @@ pub fn run() {
20022003
let compat = store::check_db_compatibility(&db_path)
20032004
.map_err(|e| format!("Cannot check database: {e}"))?;
20042005
let session_registry = Arc::new(session_runner::SessionRegistry::new());
2006+
// Backend-owned PR-poll scheduler. Managed unconditionally so the
2007+
// interest/hint commands resolve even before the store exists (e.g.
2008+
// during the needs-reset prompt); the tick loop is only spawned once
2009+
// the store is ready (the `Ok` branch below).
2010+
let pr_scheduler = Arc::new(pr_poll_scheduler::PrPollScheduler::new());
20052011

20062012
let (store_slot, reset_info) = match compat {
20072013
store::DbCompatibility::Ok => {
@@ -2024,6 +2030,13 @@ pub fn run() {
20242030
}
20252031
// Start the tiered background sync service for all cloned repos.
20262032
background_sync::spawn(Arc::clone(&store_arc), app.handle().clone());
2033+
// Start the backend PR-poll scheduler — it owns polling
2034+
// cadence/concurrency; the frontend only sends interest hints.
2035+
pr_poll_scheduler::spawn(
2036+
Arc::clone(&pr_scheduler),
2037+
Arc::clone(&store_arc),
2038+
app.handle().clone(),
2039+
);
20272040
// `fsmonitor-v1` only flips `.git/config` flags on stale
20282041
// clones the user may not visit this session — per-project
20292042
// `ensure_local_clone` already re-applies the same config
@@ -2069,6 +2082,7 @@ pub fn run() {
20692082

20702083
app.manage(store_slot);
20712084
app.manage(session_registry);
2085+
app.manage(pr_scheduler);
20722086
app.manage(Arc::new(actions::ActionExecutor::new()));
20732087
app.manage(Arc::new(actions::ActionRegistry::new()));
20742088
app.manage(ShutdownState::default());
@@ -2238,6 +2252,12 @@ pub fn run() {
22382252
prs::squash_commits,
22392253
prs::clear_branch_pr_status,
22402254
prs::recover_branch_pr,
2255+
// PR poll scheduler (frontend interest/hint layer)
2256+
pr_poll_scheduler::set_foreground_project,
2257+
pr_poll_scheduler::set_focus,
2258+
pr_poll_scheduler::set_branch_pending,
2259+
pr_poll_scheduler::refresh_now,
2260+
pr_poll_scheduler::disconnect_client,
22412261
// Utilities
22422262
util_commands::open_url,
22432263
util_commands::is_sq_available,

0 commit comments

Comments
 (0)