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
-10
@@ -445,7 +445,7 @@ func (m *Model) initAlertHuhForm() tea.Cmd {
|
||||
return m.huhForm.Init()
|
||||
}
|
||||
|
||||
func (m *Model) submitAlertForm() {
|
||||
func (m *Model) submitAlertForm() tea.Cmd {
|
||||
d := m.alertFormData
|
||||
settings := make(map[string]string)
|
||||
|
||||
@@ -486,14 +486,16 @@ func (m *Model) submitAlertForm() {
|
||||
settings["url"] = d.WebhookURL
|
||||
}
|
||||
|
||||
if m.editID > 0 {
|
||||
if err := m.store.UpdateAlert(m.editID, d.Name, d.AlertType, settings); err != nil {
|
||||
m.engine.AddLog("Update alert failed: " + err.Error())
|
||||
}
|
||||
} else {
|
||||
if err := m.store.AddAlert(d.Name, d.AlertType, settings); err != nil {
|
||||
m.engine.AddLog("Add alert failed: " + err.Error())
|
||||
}
|
||||
}
|
||||
st := m.store
|
||||
id := m.editID
|
||||
name, aType := d.Name, d.AlertType
|
||||
m.state = stateDashboard
|
||||
if id > 0 {
|
||||
return writeCmd("Update alert", func() error {
|
||||
return st.UpdateAlert(id, name, aType, settings)
|
||||
})
|
||||
}
|
||||
return writeCmd("Add alert", func() error {
|
||||
return st.AddAlert(name, aType, settings)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user