MM-24481: Use atomics for load/store of client configs (#14648)

There are 3 client config related variables which are set in regenerateClientConfig
but can be read from public methods in the App struct.

We use the same approach as the license fields in the App struct and use atomic.Value
for modifying them.

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2020-05-27 22:50:20 +05:30
коммит произвёл GitHub
родитель c35a18d15c
Коммит 79a46dd1d3
2 изменённых файлов: 9 добавлений и 10 удалений

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

@@ -72,15 +72,15 @@ func (a *App) ReloadConfig() error {
} }
func (a *App) ClientConfig() map[string]string { func (a *App) ClientConfig() map[string]string {
return a.Srv().clientConfig return a.Srv().clientConfig.Load().(map[string]string)
} }
func (a *App) ClientConfigHash() string { func (a *App) ClientConfigHash() string {
return a.Srv().clientConfigHash return a.Srv().clientConfigHash.Load().(string)
} }
func (a *App) LimitedClientConfig() map[string]string { func (a *App) LimitedClientConfig() map[string]string {
return a.Srv().limitedClientConfig return a.Srv().limitedClientConfig.Load().(map[string]string)
} }
// Registers a function with a given listener to be called when the config is reloaded and may have changed. The function // Registers a function with a given listener to be called when the config is reloaded and may have changed. The function
@@ -319,9 +319,9 @@ func (a *App) regenerateClientConfig() {
} }
clientConfigJSON, _ := json.Marshal(clientConfig) clientConfigJSON, _ := json.Marshal(clientConfig)
a.Srv().clientConfig = clientConfig a.Srv().clientConfig.Store(clientConfig)
a.Srv().limitedClientConfig = limitedClientConfig a.Srv().limitedClientConfig.Store(limitedClientConfig)
a.Srv().clientConfigHash = fmt.Sprintf("%x", md5.Sum(clientConfigJSON)) a.Srv().clientConfigHash.Store(fmt.Sprintf("%x", md5.Sum(clientConfigJSON)))
} }
func (a *App) GetCookieDomain() string { func (a *App) GetCookieDomain() string {

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

@@ -121,9 +121,9 @@ type Server struct {
pluginCommands []*PluginCommand pluginCommands []*PluginCommand
pluginCommandsLock sync.RWMutex pluginCommandsLock sync.RWMutex
clientConfig map[string]string clientConfig atomic.Value
clientConfigHash string clientConfigHash atomic.Value
limitedClientConfig map[string]string limitedClientConfig atomic.Value
diagnosticId string diagnosticId string
diagnosticClient analytics.Client diagnosticClient analytics.Client
@@ -171,7 +171,6 @@ func NewServer(options ...Option) (*Server, error) {
RootRouter: rootRouter, RootRouter: rootRouter,
LocalRouter: localRouter, LocalRouter: localRouter,
licenseListeners: map[string]func(*model.License, *model.License){}, licenseListeners: map[string]func(*model.License, *model.License){},
clientConfig: make(map[string]string),
} }
for _, option := range options { for _, option := range options {