Skip to content

Commit b36a08e

Browse files
committed
Update
1 parent 4413489 commit b36a08e

File tree

7 files changed

+192
-230
lines changed

7 files changed

+192
-230
lines changed

models/migrations/fixtures/Test_MigrateIniToDatabase/system_setting.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
# type Setting struct {
2-
# ID int64 `xorm:"pk autoincr"`
3-
# SettingKey string `xorm:"varchar(255) unique"` // key should be lowercase
4-
# SettingValue string `xorm:"text"`
5-
# Version int `xorm:"version"`
6-
# Created timeutil.TimeStamp `xorm:"created"`
7-
# Updated timeutil.TimeStamp `xorm:"updated"`
8-
# }
91
-
102
id: 1
113
setting_key: revision

models/migrations/v1_24/v316.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
package v1_24 //nolint
55

66
import (
7+
"fmt"
78
"math"
9+
"strconv"
810

911
"code.gitea.io/gitea/modules/setting"
1012
"code.gitea.io/gitea/modules/timeutil"
1113
"code.gitea.io/gitea/modules/util"
12-
1314
"xorm.io/xorm"
1415
)
1516

@@ -30,32 +31,35 @@ func (s *Setting) TableName() string {
3031
}
3132

3233
func MigrateIniToDatabase(x *xorm.Engine) error {
33-
uiMap, err := util.ConfigSectionToMap(
34-
setting.UI, "ui",
35-
[]string{
36-
"GraphMaxCommitNum", "ReactionMaxUserNum", "MaxDisplayFileSize", "DefaultShowFullName", "DefaultTheme", "Themes",
37-
"FileIconTheme", "Reactions", "CustomEmojis", "PreferredTimestampTense", "AmbiguousUnicodeDetection",
38-
}...,
39-
)
40-
if err != nil {
41-
return err
42-
}
34+
uiMap := make(map[string]string)
35+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("EXPLORE_PAGING_NUM"))] = strconv.Itoa(setting.ExplorePagingNum)
36+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("SITEMAP_PAGING_NUM"))] = strconv.Itoa(setting.SitemapPagingNum)
37+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("ISSUE_PAGING_NUM"))] = strconv.Itoa(setting.IssuePagingNum)
38+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("REPO_SEARCH_PAGING_NUM"))] = strconv.Itoa(setting.RepoSearchPagingNum)
39+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("MEMBERS_PAGING_NUM"))] = strconv.Itoa(setting.MembersPagingNum)
40+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("FEED_MAX_COMMIT_NUM"))] = strconv.Itoa(setting.FeedMaxCommitNum)
41+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("FEED_PAGING_NUM"))] = strconv.Itoa(setting.FeedPagingNum)
42+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("PACKAGES_PAGING_NUM"))] = strconv.Itoa(setting.PackagesPagingNum)
43+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("CODE_COMMENT_LINES"))] = strconv.Itoa(setting.CodeCommentLines)
44+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("SHOW_USER_EMAIL"))] = strconv.FormatBool(setting.ShowUserEmail)
45+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("SEARCH_REPO_DESCRIPTION"))] = strconv.FormatBool(setting.SearchRepoDescription)
46+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("ONLY_SHOW_RELEVANT_REPOS"))] = strconv.FormatBool(setting.OnlyShowRelevantRepos)
47+
uiMap[fmt.Sprintf("ui.%s", util.ToSnakeCase("EXPLORE_PAGING_DEFAULT_SORT"))] = fmt.Sprintf("\"%s\"", setting.ExploreDefaultSort)
4348

4449
sess := x.NewSession()
4550
defer sess.Close()
4651

47-
if err = sess.Begin(); err != nil {
52+
if err := sess.Begin(); err != nil {
4853
return err
4954
}
5055

51-
if err = sess.Sync(new(Setting)); err != nil {
56+
if err := sess.Sync(new(Setting)); err != nil {
5257
return err
5358
}
5459

5560
_ = getRevision(sess) // prepare the "revision" key ahead
5661

57-
_, err = sess.Exec("UPDATE system_setting SET version=version+1 WHERE setting_key=?", keyRevision)
58-
if err != nil {
62+
if _, err := sess.Exec("UPDATE system_setting SET version=version+1 WHERE setting_key=?", keyRevision); err != nil {
5963
return err
6064
}
6165
for k, v := range uiMap {

modules/setting/ui.go

Lines changed: 155 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -11,156 +11,143 @@ import (
1111
)
1212

1313
// UI settings
14-
var UI = struct {
15-
ExplorePagingNum int
16-
SitemapPagingNum int
17-
IssuePagingNum int
18-
RepoSearchPagingNum int
19-
MembersPagingNum int
20-
FeedMaxCommitNum int
21-
FeedPagingNum int
22-
PackagesPagingNum int
23-
GraphMaxCommitNum int
24-
CodeCommentLines int
25-
ReactionMaxUserNum int
26-
MaxDisplayFileSize int64
27-
ShowUserEmail bool
28-
DefaultShowFullName bool
29-
DefaultTheme string
30-
Themes []string
31-
FileIconTheme string
32-
Reactions []string
33-
ReactionsLookup container.Set[string] `ini:"-"`
34-
CustomEmojis []string
35-
CustomEmojisMap map[string]string `ini:"-"`
36-
SearchRepoDescription bool
37-
OnlyShowRelevantRepos bool
38-
ExploreDefaultSort string `ini:"EXPLORE_PAGING_DEFAULT_SORT"`
39-
PreferredTimestampTense string
40-
41-
AmbiguousUnicodeDetection bool
42-
43-
Notification struct {
44-
MinTimeout time.Duration
45-
TimeoutStep time.Duration
46-
MaxTimeout time.Duration
47-
EventSourceUpdateTime time.Duration
48-
} `ini:"ui.notification"`
49-
50-
SVG struct {
51-
Enabled bool `ini:"ENABLE_RENDER"`
52-
} `ini:"ui.svg"`
53-
54-
CSV struct {
55-
MaxFileSize int64
56-
MaxRows int
57-
} `ini:"ui.csv"`
58-
59-
Admin struct {
60-
UserPagingNum int
61-
RepoPagingNum int
62-
NoticePagingNum int
63-
OrgPagingNum int
64-
} `ini:"ui.admin"`
65-
User struct {
66-
RepoPagingNum int
67-
OrgPagingNum int
68-
} `ini:"ui.user"`
69-
Meta struct {
70-
Author string
71-
Description string
72-
Keywords string
73-
} `ini:"ui.meta"`
74-
}{
75-
ExplorePagingNum: 20,
76-
SitemapPagingNum: 20,
77-
IssuePagingNum: 20,
78-
RepoSearchPagingNum: 20,
79-
MembersPagingNum: 20,
80-
FeedMaxCommitNum: 5,
81-
FeedPagingNum: 20,
82-
PackagesPagingNum: 20,
83-
GraphMaxCommitNum: 100,
84-
CodeCommentLines: 4,
85-
ReactionMaxUserNum: 10,
86-
MaxDisplayFileSize: 8388608,
87-
DefaultTheme: `gitea-auto`,
88-
FileIconTheme: `material`,
89-
Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`},
90-
CustomEmojis: []string{`git`, `gitea`, `codeberg`, `gitlab`, `github`, `gogs`},
91-
CustomEmojisMap: map[string]string{"git": ":git:", "gitea": ":gitea:", "codeberg": ":codeberg:", "gitlab": ":gitlab:", "github": ":github:", "gogs": ":gogs:"},
92-
ExploreDefaultSort: "recentupdate",
93-
PreferredTimestampTense: "mixed",
94-
95-
AmbiguousUnicodeDetection: true,
96-
97-
Notification: struct {
98-
MinTimeout time.Duration
99-
TimeoutStep time.Duration
100-
MaxTimeout time.Duration
101-
EventSourceUpdateTime time.Duration
102-
}{
103-
MinTimeout: 10 * time.Second,
104-
TimeoutStep: 10 * time.Second,
105-
MaxTimeout: 60 * time.Second,
106-
EventSourceUpdateTime: 10 * time.Second,
107-
},
108-
SVG: struct {
109-
Enabled bool `ini:"ENABLE_RENDER"`
110-
}{
111-
Enabled: true,
112-
},
113-
CSV: struct {
114-
MaxFileSize int64
115-
MaxRows int
116-
}{
117-
MaxFileSize: 524288,
118-
MaxRows: 2500,
119-
},
120-
Admin: struct {
121-
UserPagingNum int
122-
RepoPagingNum int
123-
NoticePagingNum int
124-
OrgPagingNum int
125-
}{
126-
UserPagingNum: 50,
127-
RepoPagingNum: 50,
128-
NoticePagingNum: 25,
129-
OrgPagingNum: 50,
130-
},
131-
User: struct {
132-
RepoPagingNum int
133-
OrgPagingNum int
134-
}{
135-
RepoPagingNum: 15,
136-
OrgPagingNum: 15,
137-
},
138-
Meta: struct {
139-
Author string
140-
Description string
141-
Keywords string
14+
var (
15+
UI = struct {
16+
GraphMaxCommitNum int
17+
ReactionMaxUserNum int
18+
MaxDisplayFileSize int64
19+
DefaultShowFullName bool
20+
DefaultTheme string
21+
Themes []string
22+
FileIconTheme string
23+
Reactions []string
24+
ReactionsLookup container.Set[string] `ini:"-"`
25+
CustomEmojis []string
26+
CustomEmojisMap map[string]string `ini:"-"`
27+
PreferredTimestampTense string
28+
29+
AmbiguousUnicodeDetection bool
30+
31+
Notification struct {
32+
MinTimeout time.Duration
33+
TimeoutStep time.Duration
34+
MaxTimeout time.Duration
35+
EventSourceUpdateTime time.Duration
36+
} `ini:"ui.notification"`
37+
38+
SVG struct {
39+
Enabled bool `ini:"ENABLE_RENDER"`
40+
} `ini:"ui.svg"`
41+
42+
CSV struct {
43+
MaxFileSize int64
44+
MaxRows int
45+
} `ini:"ui.csv"`
46+
47+
Admin struct {
48+
UserPagingNum int
49+
RepoPagingNum int
50+
NoticePagingNum int
51+
OrgPagingNum int
52+
} `ini:"ui.admin"`
53+
User struct {
54+
RepoPagingNum int
55+
OrgPagingNum int
56+
} `ini:"ui.user"`
57+
Meta struct {
58+
Author string
59+
Description string
60+
Keywords string
61+
} `ini:"ui.meta"`
14262
}{
143-
Author: "Gitea - Git with a cup of tea",
144-
Description: "Gitea (Git with a cup of tea) is a painless self-hosted Git service written in Go",
145-
Keywords: "go,git,self-hosted,gitea",
146-
},
147-
}
63+
GraphMaxCommitNum: 100,
64+
ReactionMaxUserNum: 10,
65+
MaxDisplayFileSize: 8388608,
66+
DefaultTheme: `gitea-auto`,
67+
FileIconTheme: `material`,
68+
Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`},
69+
CustomEmojis: []string{`git`, `gitea`, `codeberg`, `gitlab`, `github`, `gogs`},
70+
CustomEmojisMap: map[string]string{"git": ":git:", "gitea": ":gitea:", "codeberg": ":codeberg:", "gitlab": ":gitlab:", "github": ":github:", "gogs": ":gogs:"},
71+
PreferredTimestampTense: "mixed",
72+
73+
AmbiguousUnicodeDetection: true,
74+
75+
Notification: struct {
76+
MinTimeout time.Duration
77+
TimeoutStep time.Duration
78+
MaxTimeout time.Duration
79+
EventSourceUpdateTime time.Duration
80+
}{
81+
MinTimeout: 10 * time.Second,
82+
TimeoutStep: 10 * time.Second,
83+
MaxTimeout: 60 * time.Second,
84+
EventSourceUpdateTime: 10 * time.Second,
85+
},
86+
SVG: struct {
87+
Enabled bool `ini:"ENABLE_RENDER"`
88+
}{
89+
Enabled: true,
90+
},
91+
CSV: struct {
92+
MaxFileSize int64
93+
MaxRows int
94+
}{
95+
MaxFileSize: 524288,
96+
MaxRows: 2500,
97+
},
98+
Admin: struct {
99+
UserPagingNum int
100+
RepoPagingNum int
101+
NoticePagingNum int
102+
OrgPagingNum int
103+
}{
104+
UserPagingNum: 50,
105+
RepoPagingNum: 50,
106+
NoticePagingNum: 25,
107+
OrgPagingNum: 50,
108+
},
109+
User: struct {
110+
RepoPagingNum int
111+
OrgPagingNum int
112+
}{
113+
RepoPagingNum: 15,
114+
OrgPagingNum: 15,
115+
},
116+
Meta: struct {
117+
Author string
118+
Description string
119+
Keywords string
120+
}{
121+
Author: "Gitea - Git with a cup of tea",
122+
Description: "Gitea (Git with a cup of tea) is a painless self-hosted Git service written in Go",
123+
Keywords: "go,git,self-hosted,gitea",
124+
},
125+
}
126+
127+
ExplorePagingNum int // Depreciated: migrated to database
128+
SitemapPagingNum int // Depreciated: migrated to database
129+
IssuePagingNum int // Depreciated: migrated to database
130+
RepoSearchPagingNum int // Depreciated: migrated to database
131+
MembersPagingNum int // Depreciated: migrated to database
132+
FeedMaxCommitNum int // Depreciated: migrated to database
133+
FeedPagingNum int // Depreciated: migrated to database
134+
PackagesPagingNum int // Depreciated: migrated to database
135+
CodeCommentLines int // Depreciated: migrated to database
136+
ShowUserEmail bool // Depreciated: migrated to database
137+
SearchRepoDescription bool // Depreciated: migrated to database
138+
OnlyShowRelevantRepos bool // Depreciated: migrated to database
139+
ExploreDefaultSort string // Depreciated: migrated to database
140+
)
148141

149142
func loadUIFrom(rootCfg ConfigProvider) {
150143
mustMapSetting(rootCfg, "ui", &UI)
151144
sec := rootCfg.Section("ui")
152-
UI.ShowUserEmail = sec.Key("SHOW_USER_EMAIL").MustBool(true)
153145
UI.DefaultShowFullName = sec.Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)
154-
UI.SearchRepoDescription = sec.Key("SEARCH_REPO_DESCRIPTION").MustBool(true)
155146

156147
if UI.PreferredTimestampTense != "mixed" && UI.PreferredTimestampTense != "absolute" {
157148
log.Fatal("ui.PREFERRED_TIMESTAMP_TENSE must be either 'mixed' or 'absolute'")
158149
}
159150

160-
// OnlyShowRelevantRepos=false is important for many private/enterprise instances,
161-
// because many private repositories do not have "description/topic", users just want to search by their names.
162-
UI.OnlyShowRelevantRepos = sec.Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false)
163-
164151
UI.ReactionsLookup = make(container.Set[string])
165152
for _, reaction := range UI.Reactions {
166153
UI.ReactionsLookup.Add(reaction)
@@ -169,4 +156,33 @@ func loadUIFrom(rootCfg ConfigProvider) {
169156
for _, emoji := range UI.CustomEmojis {
170157
UI.CustomEmojisMap[emoji] = ":" + emoji + ":"
171158
}
159+
160+
ExplorePagingNum = sec.Key("EXPLORE_PAGING_NUM").MustInt(20)
161+
deprecatedSettingDB(rootCfg, "ui", "EXPLORE_PAGING_NUM")
162+
SitemapPagingNum = sec.Key("SITEMAP_PAGING_NUM").MustInt(20)
163+
deprecatedSettingDB(rootCfg, "ui", "SITEMAP_PAGING_NUM")
164+
IssuePagingNum = sec.Key("ISSUE_PAGING_NUM").MustInt(20)
165+
deprecatedSettingDB(rootCfg, "ui", "ISSUE_PAGING_NUM")
166+
RepoSearchPagingNum = sec.Key("REPO_SEARCH_PAGING_NUM").MustInt(20)
167+
deprecatedSettingDB(rootCfg, "ui", "REPO_SEARCH_PAGING_NUM")
168+
MembersPagingNum = sec.Key("MEMBERS_PAGING_NUM").MustInt(20)
169+
deprecatedSettingDB(rootCfg, "ui", "MEMBERS_PAGING_NUM")
170+
FeedMaxCommitNum = sec.Key("FEED_MAX_COMMIT_NUM").MustInt(5)
171+
deprecatedSettingDB(rootCfg, "ui", "FEED_MAX_COMMIT_NUM")
172+
FeedPagingNum = sec.Key("FEED_PAGING_NUM").MustInt(20)
173+
deprecatedSettingDB(rootCfg, "ui", "FEED_PAGING_NUM")
174+
PackagesPagingNum = sec.Key("PACKAGES_PAGING_NUM").MustInt(20)
175+
deprecatedSettingDB(rootCfg, "ui", "PACKAGES_PAGING_NUM")
176+
CodeCommentLines = sec.Key("CODE_COMMENT_LINES").MustInt(4)
177+
deprecatedSettingDB(rootCfg, "ui", "CODE_COMMENT_LINES")
178+
ShowUserEmail = sec.Key("SHOW_USER_EMAIL").MustBool(true)
179+
deprecatedSettingDB(rootCfg, "ui", "SHOW_USER_EMAIL")
180+
SearchRepoDescription = sec.Key("SEARCH_REPO_DESCRIPTION").MustBool(true)
181+
deprecatedSettingDB(rootCfg, "ui", "SEARCH_REPO_DESCRIPTION")
182+
// OnlyShowRelevantRepos=false is important for many private/enterprise instances,
183+
// because many private repositories do not have "description/topic", users just want to search by their names.
184+
OnlyShowRelevantRepos = sec.Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false)
185+
deprecatedSettingDB(rootCfg, "ui", "ONLY_SHOW_RELEVANT_REPOS")
186+
ExploreDefaultSort = sec.Key("EXPLORE_PAGING_DEFAULT_SORT").MustString("recentupdate")
187+
deprecatedSettingDB(rootCfg, "ui", "EXPLORE_PAGING_DEFAULT_SORT")
172188
}

0 commit comments

Comments
 (0)