MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / autoRefreshData

Method autoRefreshData

internal/ui/components/auto_refresh_execution.go:91–416  ·  view source on GitHub ↗

autoRefreshData performs a lightweight refresh of performance data. snap contains the UI selections captured on the UI goroutine before this goroutine started.

(snap selSnap)

Source from the content-addressed store, hash-verified

89// autoRefreshData performs a lightweight refresh of performance data.
90// snap contains the UI selections captured on the UI goroutine before this goroutine started.
91func (a *App) autoRefreshData(snap selSnap) {
92 // Acquire the refresh guard. The countdown check in startAutoRefresh already verified
93 // isRefreshActive() == false, but we CAS here to prevent a race between that check
94 // and the actual start of the refresh.
95 token, ok := a.startRefresh()
96 if !ok {
97 a.QueueUpdateDraw(func() {
98 a.footer.SetLoading(false)
99 })
100 return
101 }
102
103 uiLogger := models.GetUILogger()
104
105 // Snapshot connection state under lock so reads are race-free.
106 conn := a.snapConn()
107
108 // Unpack UI selections captured on the UI goroutine before this goroutine was spawned.
109 hasSelectedVM := snap.hasSelectedVM
110 selectedVMID := snap.selectedVMID
111 selectedVMNode := snap.selectedVMNode
112 hasSelectedNode := snap.hasSelectedNode
113 selectedNodeName := snap.selectedNodeName
114 searchWasActive := snap.searchWasActive
115
116 if conn.isGroupMode {
117 // Group mode logic
118 ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
119 defer cancel()
120
121 nodes, vms, err := conn.groupManager.GetGroupClusterResources(ctx, true)
122 if err != nil {
123 uiLogger.Debug("Auto-refresh failed (group): %v", err)
124 a.endRefresh(token)
125 a.QueueUpdateDraw(func() {
126 a.footer.SetLoading(false)
127 })
128 return
129 }
130
131 a.QueueUpdateDraw(func() {
132 // Get current search states
133 nodeSearchState := models.GlobalState.GetSearchState(api.PageNodes)
134 vmSearchState := models.GlobalState.GetSearchState(api.PageGuests)
135
136 // Build lookup map for O(N) node detail preservation instead of O(N*M)
137 existingNodeMap := make(map[string]*api.Node, len(models.GlobalState.OriginalNodes))
138 for _, n := range models.GlobalState.OriginalNodes {
139 if n != nil {
140 existingNodeMap[n.Name+"|"+n.SourceProfile] = n
141 }
142 }
143
144 // Preserve detailed node data using map lookup
145 for _, freshNode := range nodes {
146 if freshNode == nil {
147 continue
148 }

Callers 1

Calls 15

startRefreshMethod · 0.95
snapConnMethod · 0.95
endRefreshMethod · 0.95
restoreSelectionMethod · 0.95
createSyntheticGroupMethod · 0.95
restoreSearchUIMethod · 0.95
GetUILoggerFunction · 0.92
FilterNodesFunction · 0.92
FilterVMsFunction · 0.92
FilterTasksFunction · 0.92
preserveVMEnrichmentDataFunction · 0.85

Tested by

no test coverage detected