mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-20 17:00:24 +00:00
Backport #27000 by @wxiaoguang
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.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
a9d547f55b
commit
aaf35ee49c
21 changed files with 429 additions and 525 deletions
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue