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.
This commit is contained in:
parent
0f4e1b9ac6
commit
a1c30740bb
5 changed files with 16 additions and 53 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue