@@ -25,6 +25,7 @@ export class TimeTracker implements vscode.Disposable {
2525 private focusTimeoutSeconds : number = 180 ;
2626 private gitWatcher : GitWatcher | null = null ;
2727 private branchCheckInterval : NodeJS . Timeout | null = null ;
28+ private isCheckingBranch : boolean = false ;
2829 private lastUpdateTime : number = Date . now ( ) ;
2930 private lastFocusTime : number = Date . now ( ) ;
3031 // Track time between updates for validation
@@ -445,7 +446,17 @@ export class TimeTracker implements vscode.Disposable {
445446 }
446447
447448 dispose ( ) {
448- this . stopTracking ( ) ;
449+ // Make sure all intervals are stopped
450+ this . stopTracking ( 'extension disposed' ) ;
451+
452+ // Ensure git watcher is completely stopped
453+ this . stopGitWatcher ( ) ;
454+
455+ // Clear any other potentially running intervals
456+ if ( this . saveInterval ) {
457+ clearInterval ( this . saveInterval ) ;
458+ this . saveInterval = null ;
459+ }
449460 }
450461
451462 public registerStatusBarCommand ( command : string ) {
@@ -481,6 +492,9 @@ export class TimeTracker implements vscode.Disposable {
481492 }
482493
483494 private async setupGitWatcher ( ) {
495+ // Clear any existing interval first to prevent duplicate watchers
496+ this . stopGitWatcher ( ) ;
497+
484498 try {
485499 const workspaceFolder = vscode . workspace . workspaceFolders ?. [ 0 ] ;
486500 if ( ! workspaceFolder ) {
@@ -510,10 +524,11 @@ export class TimeTracker implements vscode.Disposable {
510524 lastKnownBranch : branchInfo . current || 'unknown'
511525 } ;
512526
513- // Check for branch changes every second
527+ // Check for branch changes less frequently to reduce CPU load
528+ // Changed from 1 second to 5 seconds to reduce the number of git processes spawned
514529 this . branchCheckInterval = setInterval ( async ( ) => {
515530 await this . checkBranchChanges ( ) ;
516- } , 1000 ) ;
531+ } , 5000 ) ;
517532
518533 } catch ( error ) {
519534 this . logger . logEvent ( 'branch_check_error' , {
@@ -529,11 +544,13 @@ export class TimeTracker implements vscode.Disposable {
529544 }
530545
531546 private async checkBranchChanges ( ) {
532- if ( ! this . gitWatcher || ! this . isTracking ) {
547+ // Prevent concurrent executions of branch checking
548+ if ( this . isCheckingBranch || ! this . gitWatcher || ! this . isTracking ) {
533549 return ;
534550 }
535551
536552 try {
553+ this . isCheckingBranch = true ;
537554 const branchInfo = await this . gitWatcher . git . branch ( ) ;
538555 const currentBranch = branchInfo . current || 'unknown' ;
539556
@@ -566,6 +583,9 @@ export class TimeTracker implements vscode.Disposable {
566583 location : 'checkBranchChanges'
567584 } ) ;
568585 console . error ( 'Error checking branch changes:' , error ) ;
586+ } finally {
587+ // Always reset the flag to allow future checks
588+ this . isCheckingBranch = false ;
569589 }
570590 }
571591
0 commit comments