Config: Refactor initSettings() and initHub()
This prevents redundant initialization when called repeatedly.
This commit is contained in:
parent
39b0530313
commit
2f5d1fea50
2 changed files with 10 additions and 6 deletions
|
@ -600,6 +600,10 @@ func (c *Config) UpdateHub() {
|
|||
|
||||
// initHub initializes PhotoPrism hub config.
|
||||
func (c *Config) initHub() {
|
||||
if c.hub != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.hub = hub.NewConfig(c.Version(), c.HubConfigFile(), c.serial, c.env, c.UserAgent(), c.options.PartnerID)
|
||||
|
||||
if err := c.hub.Load(); err == nil {
|
||||
|
@ -626,9 +630,7 @@ func (c *Config) initHub() {
|
|||
|
||||
// Hub returns the PhotoPrism hub config.
|
||||
func (c *Config) Hub() *hub.Config {
|
||||
if c.hub == nil {
|
||||
c.initHub()
|
||||
}
|
||||
c.initHub()
|
||||
|
||||
return c.hub
|
||||
}
|
||||
|
|
|
@ -218,6 +218,10 @@ func (s *Settings) Save(fileName string) error {
|
|||
|
||||
// initSettings initializes user settings from a config file.
|
||||
func (c *Config) initSettings() {
|
||||
if c.settings != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.settings = NewSettings(c)
|
||||
fileName := c.SettingsFile()
|
||||
|
||||
|
@ -236,9 +240,7 @@ func (c *Config) initSettings() {
|
|||
|
||||
// Settings returns the current user settings.
|
||||
func (c *Config) Settings() *Settings {
|
||||
if c.settings == nil {
|
||||
c.initSettings()
|
||||
}
|
||||
c.initSettings()
|
||||
|
||||
if c.DisablePlaces() {
|
||||
c.settings.Features.Places = false
|
||||
|
|
Loading…
Reference in a new issue