diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-01-02 00:06:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-02 00:06:52 +0800 |
commit | a1c30740bb04ed55905415dcd195ee9fb97547de (patch) | |
tree | 60dd79afebadd9d092b84d790a1cf4678c4619d4 /models/system/setting.go | |
parent | 0f4e1b9ac66b8ffa0083a5a2516e4710393bb0da (diff) | |
download | gitea-a1c30740bb04ed55905415dcd195ee9fb97547de.tar.gz gitea-a1c30740bb04ed55905415dcd195ee9fb97547de.zip |
Fix get system setting bug when enabled redis cache (#22295)
Fix #22281
In #21621 , `Get[V]` and `Set[V]` has been introduced, so that cache
value will be `*Setting`. For memory cache it's OK. But for redis cache,
it can only store `string` for the current implementation. This PR
revert some of changes of that and just store or return a `string` for
system setting.
Diffstat (limited to 'models/system/setting.go')
-rw-r--r-- | models/system/setting.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/models/system/setting.go b/models/system/setting.go index 6f333d6fd1..8e16547d92 100644 --- a/models/system/setting.go +++ b/models/system/setting.go @@ -92,13 +92,13 @@ func GetSettingNoCache(key string) (*Setting, error) { } // GetSetting returns the setting value via the key -func GetSetting(key string) (*Setting, error) { - return cache.Get(genSettingCacheKey(key), func() (*Setting, error) { +func GetSetting(key string) (string, error) { + return cache.GetString(genSettingCacheKey(key), func() (string, error) { res, err := GetSettingNoCache(key) if err != nil { - return nil, err + return "", err } - return res, nil + return res.SettingValue, nil }) } @@ -106,7 +106,8 @@ func GetSetting(key string) (*Setting, error) { // none existing keys and errors are ignored and result in false func GetSettingBool(key string) bool { s, _ := GetSetting(key) - return s.GetValueBool() + v, _ := strconv.ParseBool(s) + return v } // GetSettings returns specific settings @@ -183,8 +184,8 @@ func SetSettingNoVersion(key, value string) error { // SetSetting updates a users' setting for a specific key func SetSetting(setting *Setting) error { - _, err := cache.Set(genSettingCacheKey(setting.SettingKey), func() (*Setting, error) { - return setting, upsertSettingValue(strings.ToLower(setting.SettingKey), setting.SettingValue, setting.Version) + _, err := cache.GetString(genSettingCacheKey(setting.SettingKey), func() (string, error) { + return setting.SettingValue, upsertSettingValue(strings.ToLower(setting.SettingKey), setting.SettingValue, setting.Version) }) if err != nil { return err |