1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-08-03 00:45:22 +02:00

Add system setting table with cache and also add cache supports for user setting (#18058)

This commit is contained in:
Lunny Xiao 2022-10-17 07:29:26 +08:00 committed by GitHub
parent 5d3dbffa15
commit f860a6d2e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 1117 additions and 436 deletions

View file

@ -31,6 +31,34 @@ func init() {
db.RegisterModel(new(Setting))
}
// ErrUserSettingIsNotExist represents an error that a setting is not exist with special key
type ErrUserSettingIsNotExist struct {
Key string
}
// Error implements error
func (err ErrUserSettingIsNotExist) Error() string {
return fmt.Sprintf("Setting[%s] is not exist", err.Key)
}
// IsErrUserSettingIsNotExist return true if err is ErrSettingIsNotExist
func IsErrUserSettingIsNotExist(err error) bool {
_, ok := err.(ErrUserSettingIsNotExist)
return ok
}
// GetSetting returns specific setting
func GetSetting(uid int64, key string) (*Setting, error) {
v, err := GetUserSettings(uid, []string{key})
if err != nil {
return nil, err
}
if len(v) == 0 {
return nil, ErrUserSettingIsNotExist{key}
}
return v[key], nil
}
// GetUserSettings returns specific settings from user
func GetUserSettings(uid int64, keys []string) (map[string]*Setting, error) {
settings := make([]*Setting, 0, len(keys))