MM-14145: The config store Set will now Save automatically (#10377)

* MM-14145: The config store Set will now Save automatically

When UpdateConfig (and configStore.Set) is called in admin.go and
config.go, commonStore.Set now takes a store-specific persist function.
It uses that persist function to save the configuration automatically.

Removed: Now callers do not have to call configStore.Save or
app.PersistConfig, and those functions have been removed.

Possible downside: this means a "failed to persist config" error can now
be thrown during a app.UpdateConfig or commonStore.Set call. But
considering application code never really sets a config without saving
it (except in the test cases, which were testing that -- see below), it
seems fine to group these responsibilities.

Also removed: tests for 'set without save'. Since that can not happen
anymore, the tests are not needed.

* Removed Save completely, cleaned up formatting, joined save test with
set tests.

* fixed shadowed variable error
Этот коммит содержится в:
Christopher Poile
2019-02-28 10:51:42 -05:00
коммит произвёл Jesse Hallam
родитель 06261d32ba
Коммит 8bd182c38f
11 изменённых файлов: 39 добавлений и 107 удалений

Просмотреть файл

@@ -168,7 +168,6 @@ func (a *App) SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bo
return model.NewAppError("saveConfig", "app.save_config.app_error", nil, err.Error(), http.StatusInternalServerError)
}
a.PersistConfig()
if a.Metrics != nil {
if *a.Config().MetricsSettings.Enable {
a.Metrics.StartServer()

Просмотреть файл

@@ -56,12 +56,6 @@ func (a *App) UpdateConfig(f func(*model.Config)) {
a.Srv.UpdateConfig(f)
}
func (a *App) PersistConfig() {
if err := a.Srv.configStore.Save(); err != nil {
mlog.Error("Failed to persist config", mlog.Err(err))
}
}
func (s *Server) ReloadConfig() error {
debug.FreeOSMemory()
if err := s.configStore.Load(); err != nil {

Просмотреть файл

@@ -65,7 +65,6 @@ func (a *App) AddSamlPublicCertificate(fileData *multipart.FileHeader) *model.Ap
}
a.UpdateConfig(func(dest *model.Config) { *dest = *cfg })
a.PersistConfig()
return nil
}
@@ -83,7 +82,6 @@ func (a *App) AddSamlPrivateCertificate(fileData *multipart.FileHeader) *model.A
}
a.UpdateConfig(func(dest *model.Config) { *dest = *cfg })
a.PersistConfig()
return nil
}
@@ -101,7 +99,6 @@ func (a *App) AddSamlIdpCertificate(fileData *multipart.FileHeader) *model.AppEr
}
a.UpdateConfig(func(dest *model.Config) { *dest = *cfg })
a.PersistConfig()
return nil
}
@@ -128,7 +125,6 @@ func (a *App) RemoveSamlPublicCertificate() *model.AppError {
}
a.UpdateConfig(func(dest *model.Config) { *dest = *cfg })
a.PersistConfig()
return nil
}
@@ -147,7 +143,6 @@ func (a *App) RemoveSamlPrivateCertificate() *model.AppError {
}
a.UpdateConfig(func(dest *model.Config) { *dest = *cfg })
a.PersistConfig()
return nil
}
@@ -166,7 +161,6 @@ func (a *App) RemoveSamlIdpCertificate() *model.AppError {
}
a.UpdateConfig(func(dest *model.Config) { *dest = *cfg })
a.PersistConfig()
return nil
}