mirror of
https://github.com/mattermost/mattermost.git
synced 2026-09-24 16:05:00 +08:00
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>
This commit is contained in:
co-authored by
mattermod
parent
c35a18d15c
commit
79a46dd1d3
+6
-6
@@ -72,15 +72,15 @@ func (a *App) ReloadConfig() error {
|
||||
}
|
||||
|
||||
func (a *App) ClientConfig() map[string]string {
|
||||
return a.Srv().clientConfig
|
||||
return a.Srv().clientConfig.Load().(map[string]string)
|
||||
}
|
||||
|
||||
func (a *App) ClientConfigHash() string {
|
||||
return a.Srv().clientConfigHash
|
||||
return a.Srv().clientConfigHash.Load().(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
|
||||
@@ -319,9 +319,9 @@ func (a *App) regenerateClientConfig() {
|
||||
}
|
||||
|
||||
clientConfigJSON, _ := json.Marshal(clientConfig)
|
||||
a.Srv().clientConfig = clientConfig
|
||||
a.Srv().limitedClientConfig = limitedClientConfig
|
||||
a.Srv().clientConfigHash = fmt.Sprintf("%x", md5.Sum(clientConfigJSON))
|
||||
a.Srv().clientConfig.Store(clientConfig)
|
||||
a.Srv().limitedClientConfig.Store(limitedClientConfig)
|
||||
a.Srv().clientConfigHash.Store(fmt.Sprintf("%x", md5.Sum(clientConfigJSON)))
|
||||
}
|
||||
|
||||
func (a *App) GetCookieDomain() string {
|
||||
|
||||
+3
-4
@@ -121,9 +121,9 @@ type Server struct {
|
||||
pluginCommands []*PluginCommand
|
||||
pluginCommandsLock sync.RWMutex
|
||||
|
||||
clientConfig map[string]string
|
||||
clientConfigHash string
|
||||
limitedClientConfig map[string]string
|
||||
clientConfig atomic.Value
|
||||
clientConfigHash atomic.Value
|
||||
limitedClientConfig atomic.Value
|
||||
|
||||
diagnosticId string
|
||||
diagnosticClient analytics.Client
|
||||
@@ -171,7 +171,6 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
RootRouter: rootRouter,
|
||||
LocalRouter: localRouter,
|
||||
licenseListeners: map[string]func(*model.License, *model.License){},
|
||||
clientConfig: make(map[string]string),
|
||||
}
|
||||
|
||||
for _, option := range options {
|
||||
|
||||
Reference in New Issue
Block a user