@@ -19,7 +19,7 @@ import { RefreshController } from "@/browser/utils/RefreshController";
1919 * - Lives outside React lifecycle (stable references)
2020 * - Event-driven updates (no polling):
2121 * - Initial subscription triggers immediate fetch
22- * - File-modifying tools trigger debounced refresh (3s )
22+ * - File-modifying tools trigger debounced refresh (1s active, 3s background )
2323 * - Window focus triggers refresh for visible workspaces
2424 * - Explicit invalidation (branch switch, etc.)
2525 * - Manages git fetch with exponential backoff
@@ -31,6 +31,7 @@ import { RefreshController } from "@/browser/utils/RefreshController";
3131
3232// Configuration
3333const MAX_CONCURRENT_GIT_OPS = 5 ;
34+ const ACTIVE_WORKSPACE_DEBOUNCE_MS = 1000 ; // 1s for active workspace (vs 3s background)
3435
3536// Fetch configuration - aggressive intervals for fresh data
3637const FETCH_BASE_INTERVAL_MS = 3 * 1000 ; // 3 seconds
@@ -53,7 +54,12 @@ export class GitStatusStore {
5354 // File modification subscription
5455 private fileModifyUnsubscribe : ( ( ) => void ) | null = null ;
5556
57+ // Active workspace gets faster refresh (1s vs 3s debounce)
58+ private activeWorkspaceId : string | null = null ;
59+ private activeWorkspaceTimer : ReturnType < typeof setTimeout > | null = null ;
60+
5661 // RefreshController handles debouncing, focus/visibility, and in-flight guards
62+ // Used for background workspaces (3s debounce)
5763 private readonly refreshController : RefreshController ;
5864
5965 setClient ( client : RouterClient < AppRouter > ) {
@@ -113,6 +119,14 @@ export class GitStatusStore {
113119 } ) ;
114120 }
115121
122+ /**
123+ * Set the active workspace for prioritized refresh (1s debounce vs 3s).
124+ * Call when workspace selection changes.
125+ */
126+ setActiveWorkspace ( workspaceId : string | null ) : void {
127+ this . activeWorkspaceId = workspaceId ;
128+ }
129+
116130 /**
117131 * Invalidate status for a workspace, clearing cache and triggering immediate refresh.
118132 * Call after operations that change git state (e.g., branch switch).
@@ -468,6 +482,10 @@ export class GitStatusStore {
468482 this . fetchCache . clear ( ) ;
469483 this . fileModifyUnsubscribe ?.( ) ;
470484 this . fileModifyUnsubscribe = null ;
485+ if ( this . activeWorkspaceTimer ) {
486+ clearTimeout ( this . activeWorkspaceTimer ) ;
487+ this . activeWorkspaceTimer = null ;
488+ }
471489 this . refreshController . dispose ( ) ;
472490 }
473491
@@ -490,8 +508,19 @@ export class GitStatusStore {
490508 return ;
491509 }
492510
493- // RefreshController handles debouncing, focus gating, and in-flight guards
494- this . refreshController . schedule ( ) ;
511+ // Active workspace gets faster refresh (1s) via dedicated timer
512+ if ( workspaceId === this . activeWorkspaceId ) {
513+ if ( this . activeWorkspaceTimer ) {
514+ clearTimeout ( this . activeWorkspaceTimer ) ;
515+ }
516+ this . activeWorkspaceTimer = setTimeout ( ( ) => {
517+ this . activeWorkspaceTimer = null ;
518+ this . refreshController . requestImmediate ( ) ;
519+ } , ACTIVE_WORKSPACE_DEBOUNCE_MS ) ;
520+ } else {
521+ // Background workspaces use standard 3s debounce via RefreshController
522+ this . refreshController . schedule ( ) ;
523+ }
495524 } ) ;
496525 }
497526}
@@ -542,3 +571,11 @@ export function invalidateGitStatus(workspaceId: string): void {
542571 const store = getGitStoreInstance ( ) ;
543572 store . invalidateWorkspace ( workspaceId ) ;
544573}
574+
575+ /**
576+ * Set the active workspace for prioritized git status refresh (1s vs 3s debounce).
577+ */
578+ export function setActiveWorkspace ( workspaceId : string | null ) : void {
579+ const store = getGitStoreInstance ( ) ;
580+ store . setActiveWorkspace ( workspaceId ) ;
581+ }
0 commit comments