@@ -611,7 +611,36 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
611611 outgoing := make ([]PR , len (app .outgoing ))
612612 copy (outgoing , app .outgoing )
613613 previousBlocked := app .previousBlockedPRs
614- blockedTimes := app .blockedPRTimes
614+
615+ // Clean up blockedPRTimes first to remove stale entries
616+ // Only keep blocked times for PRs that are actually in the current lists
617+ cleanedBlockedTimes := make (map [string ]time.Time )
618+ for i := range app .incoming {
619+ if blockTime , exists := app .blockedPRTimes [app .incoming [i ].URL ]; exists {
620+ cleanedBlockedTimes [app .incoming [i ].URL ] = blockTime
621+ }
622+ }
623+ for i := range app .outgoing {
624+ if blockTime , exists := app .blockedPRTimes [app .outgoing [i ].URL ]; exists {
625+ cleanedBlockedTimes [app .outgoing [i ].URL ] = blockTime
626+ }
627+ }
628+
629+ // Log any removed entries
630+ removedCount := 0
631+ for url := range app .blockedPRTimes {
632+ if _ , exists := cleanedBlockedTimes [url ]; ! exists {
633+ log .Printf ("[BLOCKED] Removing stale blocked time for PR no longer in list: %s" , url )
634+ removedCount ++
635+ }
636+ }
637+ if removedCount > 0 {
638+ log .Printf ("[BLOCKED] Cleaned up %d stale blocked PR times" , removedCount )
639+ }
640+
641+ // Update the app's blockedPRTimes to the cleaned version to prevent memory growth
642+ app .blockedPRTimes = cleanedBlockedTimes
643+ blockedTimes := cleanedBlockedTimes
615644 autoBrowserEnabled := app .enableAutoBrowser
616645 startTime := app .startTime
617646 hideStaleIncoming := app .hideStaleIncoming
@@ -688,27 +717,10 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
688717 }
689718 }
690719
691- // Clean up blockedPRTimes to only include PRs that are currently in the lists
692- // This ensures merged/closed PRs don't persist
693- cleanedBlockedTimes := make (map [string ]time.Time )
694- var removedCount int
695- for url , blockTime := range newBlockedTimes {
696- // Only keep blocked times for PRs that are still in current lists
697- if currentBlocked [url ] {
698- cleanedBlockedTimes [url ] = blockTime
699- } else {
700- removedCount ++
701- log .Printf ("[BLOCKED] Removing stale blocked time for PR no longer in list: %s" , url )
702- }
703- }
704- if removedCount > 0 {
705- log .Printf ("[BLOCKED] Cleaned up %d stale blocked PR times (likely merged/closed)" , removedCount )
706- }
707-
708720 // Update state with a lock
709721 app .mu .Lock ()
710722 app .previousBlockedPRs = currentBlocked
711- app .blockedPRTimes = cleanedBlockedTimes
723+ app .blockedPRTimes = newBlockedTimes
712724 // Update the PR lists with FirstBlockedAt times
713725 app .incoming = incoming
714726 app .outgoing = outgoing
0 commit comments