diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-10-05 09:08:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-05 09:08:19 +0800 |
commit | 9f8d59858af581a2c278a4896a301339991ece5b (patch) | |
tree | 577a395a442ccd9579dfd2726750301e6a934ef3 /models/migrations | |
parent | 976d1760ac483a6f5fa8fa5ad24d94cae58497eb (diff) | |
download | gitea-9f8d59858af581a2c278a4896a301339991ece5b.tar.gz gitea-9f8d59858af581a2c278a4896a301339991ece5b.zip |
Refactor system setting (#27000)
This PR reduces the complexity of the system setting system.
It only needs one line to introduce a new option, and the option can be
used anywhere out-of-box.
It is still high-performant (and more performant) because the config
values are cached in the config system.
Diffstat (limited to 'models/migrations')
-rw-r--r-- | models/migrations/v1_18/v227.go | 42 |
1 files changed, 1 insertions, 41 deletions
diff --git a/models/migrations/v1_18/v227.go b/models/migrations/v1_18/v227.go index 78c80f74ec..5fe5dcd0c9 100644 --- a/models/migrations/v1_18/v227.go +++ b/models/migrations/v1_18/v227.go @@ -4,10 +4,6 @@ package v1_18 //nolint import ( - "fmt" - "strconv" - - "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" "xorm.io/xorm" @@ -22,42 +18,6 @@ type SystemSetting struct { Updated timeutil.TimeStamp `xorm:"updated"` } -func insertSettingsIfNotExist(x *xorm.Engine, sysSettings []*SystemSetting) error { - sess := x.NewSession() - defer sess.Close() - if err := sess.Begin(); err != nil { - return err - } - for _, setting := range sysSettings { - exist, err := sess.Table("system_setting").Where("setting_key=?", setting.SettingKey).Exist() - if err != nil { - return err - } - if !exist { - if _, err := sess.Insert(setting); err != nil { - return err - } - } - } - return sess.Commit() -} - func CreateSystemSettingsTable(x *xorm.Engine) error { - if err := x.Sync(new(SystemSetting)); err != nil { - return fmt.Errorf("sync2: %w", err) - } - - // migrate xx to database - sysSettings := []*SystemSetting{ - { - SettingKey: "picture.disable_gravatar", - SettingValue: strconv.FormatBool(setting.DisableGravatar), - }, - { - SettingKey: "picture.enable_federated_avatar", - SettingValue: strconv.FormatBool(setting.EnableFederatedAvatar), - }, - } - - return insertSettingsIfNotExist(x, sysSettings) + return x.Sync(new(SystemSetting)) } |