perf(tui): precompute maintenance set, eliminate redundant GetAllSites
Replace O(windows × sites) isMonitorInMaintenance with O(1) map lookup. buildMaintSet runs once per refreshLive/handleTabData, not per call site. groupSparkline/groupUptime now use m.sites (already on model) instead of calling engine.GetAllSites() which copies the full map under a mutex.
This commit was merged in pull request #172.
This commit is contained in:
@@ -21,27 +21,36 @@ type maintFormData struct {
|
||||
}
|
||||
|
||||
func (m Model) isMonitorInMaintenance(monitorID int) bool {
|
||||
return m.maintSet[monitorID]
|
||||
}
|
||||
|
||||
func (m *Model) buildMaintSet() {
|
||||
set := make(map[int]bool)
|
||||
now := time.Now()
|
||||
for _, mw := range m.maintenanceWindows {
|
||||
if mw.Type != "maintenance" {
|
||||
continue
|
||||
}
|
||||
now := time.Now()
|
||||
if mw.StartTime.After(now) {
|
||||
continue
|
||||
}
|
||||
if !mw.EndTime.IsZero() && mw.EndTime.Before(now) {
|
||||
continue
|
||||
}
|
||||
if mw.MonitorID == 0 || mw.MonitorID == monitorID {
|
||||
return true
|
||||
if mw.MonitorID == 0 {
|
||||
for _, s := range m.sites {
|
||||
set[s.ID] = true
|
||||
}
|
||||
break
|
||||
}
|
||||
set[mw.MonitorID] = true
|
||||
for _, s := range m.sites {
|
||||
if s.ID == monitorID && s.ParentID > 0 && mw.MonitorID == s.ParentID {
|
||||
return true
|
||||
if s.ParentID == mw.MonitorID {
|
||||
set[s.ID] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
m.maintSet = set
|
||||
}
|
||||
|
||||
func (m *Model) initMaintHuhForm() tea.Cmd {
|
||||
|
||||
Reference in New Issue
Block a user