refactor(models): split Site into SiteConfig + SiteState
Site now embeds SiteConfig (22 persistent fields) and SiteState (11 ephemeral runtime fields). Field access unchanged via promotion — site.Name and site.Status still work. Store layer deals exclusively in SiteConfig — the DB never sees runtime state. Engine's liveState keeps full Site composites. UpdateSiteConfig reduced from 11-line field-by-field copy to `existing.SiteConfig = cfg`. RunCheck takes SiteConfig (only needs config fields). Checker is now statically prevented from reading/writing runtime state. Backup.Sites changed to []SiteConfig — exports no longer carry zero-valued runtime fields. Import backward-compatible (json ignores unknown fields).
This commit was merged in pull request #109.
This commit is contained in:
@@ -535,7 +535,7 @@ func (m *Model) submitSiteForm() tea.Cmd {
|
||||
threshold = 7
|
||||
}
|
||||
|
||||
site := models.Site{
|
||||
cfg := models.SiteConfig{
|
||||
ID: m.editID,
|
||||
Name: d.Name,
|
||||
URL: d.URL,
|
||||
@@ -559,11 +559,8 @@ func (m *Model) submitSiteForm() tea.Cmd {
|
||||
st := m.store
|
||||
m.state = stateDashboard
|
||||
if m.editID > 0 {
|
||||
// The engine's in-memory config updates immediately; the DB write
|
||||
// follows in the Cmd. New sites enter the engine via its poll loop
|
||||
// once the insert lands.
|
||||
m.engine.UpdateSiteConfig(site)
|
||||
return writeCmd("Update site", func() error { return st.UpdateSite(context.Background(), site) })
|
||||
m.engine.UpdateSiteConfig(cfg)
|
||||
return writeCmd("Update site", func() error { return st.UpdateSite(context.Background(), cfg) })
|
||||
}
|
||||
return writeCmd("Add site", func() error { return st.AddSite(context.Background(), site) })
|
||||
return writeCmd("Add site", func() error { return st.AddSite(context.Background(), cfg) })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user