fix(tui): move all store writes out of Update into tea.Cmds
Deletes, pause toggles, maintenance end, theme/collapse prefs, and all four form submits wrote to the store synchronously on the UI goroutine; with busy_timeout=5000 a contended DB froze input for up to 5s. Writes now run through a writeCmd helper returning writeDoneMsg. The in-memory engine/model mutations stay in Update so rows react instantly; the reply logs failures and reloads tab data, so the UI converges on what was actually written. Closures capture snapshotted values only — never the model.
This commit was merged in pull request #102.
This commit is contained in:
+12
-2
@@ -27,7 +27,9 @@ func loadCollapsed(s store.Store) map[int]bool {
|
||||
return m
|
||||
}
|
||||
|
||||
func saveCollapsed(s store.Store, collapsed map[int]bool) {
|
||||
// collapsedJSON snapshots the collapsed-group set for persistence. Marshaling
|
||||
// happens on the UI goroutine so the write Cmd never reads the live map.
|
||||
func collapsedJSON(collapsed map[int]bool) string {
|
||||
var ids []int
|
||||
for id, v := range collapsed {
|
||||
if v {
|
||||
@@ -35,7 +37,15 @@ func saveCollapsed(s store.Store, collapsed map[int]bool) {
|
||||
}
|
||||
}
|
||||
data, _ := json.Marshal(ids)
|
||||
_ = s.SetPreference("collapsed_groups", string(data))
|
||||
return string(data)
|
||||
}
|
||||
|
||||
// writeCmd runs a store mutation off the UI goroutine. The closure must only
|
||||
// capture values snapshotted in Update — never the model itself.
|
||||
func writeCmd(op string, fn func() error) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
return writeDoneMsg{op: op, err: fn()}
|
||||
}
|
||||
}
|
||||
|
||||
func sortSitesForDisplay(allSites []models.Site, collapsed map[int]bool) []models.Site {
|
||||
|
||||
Reference in New Issue
Block a user