Config: persist settings immediately on site update (#31754)

This commit is contained in:
Michael Geers 2026-07-13 11:43:51 +02:00 • committed by GitHub
parent 83a2b7de23
commit 43627f6649
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View file

@ -669,7 +669,7 @@ func configureDatabase(conf globalconfig.DB) error {
// persist unsaved settings on shutdown
shutdown.Register(persistSettings)
// persist unsaved settings every 30 minutes
// persist unsaved settings every minute
go func() {
for range time.Tick(time.Minute) {
persistSettings()

View file

@ -4,6 +4,7 @@ import (
"net/http"
"github.com/evcc-io/evcc/core/site"
"github.com/evcc-io/evcc/server/db/settings"
"github.com/evcc-io/evcc/util/config"
)
@ -118,6 +119,12 @@ func updateSiteHandler(site site.API) http.HandlerFunc {
setConfigDirty()
}
// persist immediately to keep meter refs consistent with device config on unclean shutdown
if err := settings.Persist(); err != nil {
jsonError(w, http.StatusInternalServerError, err)
return
}
status := map[bool]int{false: http.StatusOK, true: http.StatusAccepted}
w.WriteHeader(status[ConfigDirty()])
}