fix(tui): move blocking DB IO out of Update/View into tea.Cmds #101
Reference in New Issue
Block a user
Delete Branch "fix/tui-io-mvu"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Final phase of the fresh-eyes first-cut backlog. Makes the TUI data flow idiomatic MVU — no database IO on the UI goroutine.
Problem
handleTickcalledrefreshDataevery second, issuing 4 blocking SQLite queries (GetAllAlerts/GetAllUsers/GetAllNodes/GetAllMaintenanceWindows) on the UI goroutine, errors swallowed.viewDetailPanelranGetStateChanges— a DB query — insideView(), on every render (tick, keypress, mouse).A slow disk stalled input and animation.
Fix
refreshData→refreshLive()(in-memory engine copies only: sites + logs; safe every tick) andloadTabDataCmd(), atea.Cmdthat loads the 4 DB tables off the UI goroutine and returns atabDataMsg.handleTickrefreshes live state every tick but dispatches the tab-data load only when stale (tabRefreshTTL= 5s) — tab-bar counts stay fresh without a per-second storm. Errors now log; a transient failure keeps previous data instead of blanking the view.loadDetailCmd, cached on the model;viewDetailPanelreads the cache —Viewno longer touches the DB.Initkicks an initial load (no empty first frame); the baretime.Timetick becomes a namedtickMsg; the test-alert raw goroutine becomes atea.Cmd.Tests
The package's first
Update()-driven tests: tab-data load + apply, error-keeps-previous-data, detail cache with a store-hit counter provingViewdoes zero IO across repeated renders, and thehandleTickthrottle. Full suite green under-race; golangci-lint clean locally.Phase 4 of the fresh-eyes first-cut backlog (builds on #98, #99, #100).