From e1feb33f0a791bd7efe4fb870e27374d94e7c39f Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Wed, 23 Oct 2024 03:20:48 +0300 Subject: [PATCH] perf: only load config once --- config/config.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/config.go b/config/config.go index d722966..979817e 100644 --- a/config/config.go +++ b/config/config.go @@ -14,6 +14,8 @@ type Config struct { WindowHeight int `json:"windowHeight"` } +var config *Config + func (c *Config) Save() { configDir := common.GetConfigDir() configPath := GetConfigPath() @@ -31,6 +33,7 @@ func (c *Config) Save() { panic(err) } f.WriteString(string(json)) + config = c logger.Info("Config saved in: %s", configPath) } @@ -48,6 +51,9 @@ func GetConfigPath() string { } func GetConfig() Config { + if config != nil { + return *config + } configPath := GetConfigPath() if _, err := os.Stat(configPath); os.IsNotExist(err) { logger.Warn("Config file not found: %s", configPath)