File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -561,19 +561,32 @@ struct QueryTab: Identifiable, Equatable {
561561/// Manager for query tabs
562562@MainActor @Observable
563563final class QueryTabManager {
564- var tabs : [ QueryTab ] = [ ]
564+ var tabs : [ QueryTab ] = [ ] {
565+ didSet { _tabIndexMapDirty = true }
566+ }
567+
565568 var selectedTabId : UUID ?
566569
570+ @ObservationIgnored private var _tabIndexMap : [ UUID : Int ] = [ : ]
571+ @ObservationIgnored private var _tabIndexMapDirty = true
572+
573+ private func rebuildTabIndexMapIfNeeded( ) {
574+ guard _tabIndexMapDirty else { return }
575+ _tabIndexMap = Dictionary ( uniqueKeysWithValues: tabs. enumerated ( ) . map { ( $1. id, $0) } )
576+ _tabIndexMapDirty = false
577+ }
578+
567579 var tabIds : [ UUID ] { tabs. map ( \. id) }
568580
569581 var selectedTab : QueryTab ? {
570- guard let id = selectedTabId else { return tabs. first }
571- return tabs . first { $0 . id == id }
582+ if let index = selectedTabIndex { return tabs [ index ] }
583+ return selectedTabId == nil ? tabs . first : nil
572584 }
573585
574586 var selectedTabIndex : Int ? {
575587 guard let id = selectedTabId else { return nil }
576- return tabs. firstIndex { $0. id == id }
588+ rebuildTabIndexMapIfNeeded ( )
589+ return _tabIndexMap [ id]
577590 }
578591
579592 init ( ) {
Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ final class MainContentCoordinator {
9797 var needsLazyLoad = false
9898
9999 /// Cache for async-sorted query tab rows (large datasets sorted on background thread)
100- private( set) var querySortCache : [ UUID : QuerySortCacheEntry ] = [ : ]
100+ @ ObservationIgnored private( set) var querySortCache : [ UUID : QuerySortCacheEntry ] = [ : ]
101101
102102 // MARK: - Internal State
103103
@@ -134,7 +134,7 @@ final class MainContentCoordinator {
134134
135135 /// True while a database switch is in progress. Guards against
136136 /// side-effect window creation during the switch cascade.
137- var isSwitchingDatabase = false
137+ @ ObservationIgnored var isSwitchingDatabase = false
138138
139139 /// True once the coordinator's view has appeared (onAppear fired).
140140 /// Coordinators that SwiftUI creates during body re-evaluation but never
You can’t perform that action at this time.
0 commit comments