Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use buffersize to reduce database connection when iterate #2724

Merged
merged 4 commits into from
Oct 21, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ SSL_MODE = disable
PATH = data/gitea.db
; For "sqlite3" only. Query timeout
SQLITE_TIMEOUT = 500
; For iterate buffer, default is 50
ITERATE_BUFFER_SIZE = 50

[indexer]
ISSUE_INDEXER_PATH = indexers/issues.bleve
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v19.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func generateAndMigrateGitHooks(x *xorm.Engine) (err error) {
}
)

return x.Where("id > 0").Iterate(new(Repository),
return x.Where("id > 0").BufferSize(setting.IterateBufferSize).Iterate(new(Repository),
func(idx int, bean interface{}) error {
repo := bean.(*Repository)
user := new(User)
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v22.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func generateAndMigrateWikiGitHooks(x *xorm.Engine) (err error) {
}
)

return x.Where("id > 0").Iterate(new(Repository),
return x.Where("id > 0").BufferSize(setting.IterateBufferSize).Iterate(new(Repository),
func(idx int, bean interface{}) error {
repo := bean.(*Repository)
user := new(User)
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v26.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func generateAndMigrateGitHookChains(x *xorm.Engine) (err error) {
hookTpl = fmt.Sprintf("#!/usr/bin/env %s\ndata=$(cat)\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\necho \"${data}\" | \"${hook}\"\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType)
)

return x.Where("id > 0").Iterate(new(Repository),
return x.Where("id > 0").BufferSize(setting.IterateBufferSize).Iterate(new(Repository),
func(idx int, bean interface{}) error {
repo := bean.(*Repository)
user := new(User)
Expand Down
4 changes: 2 additions & 2 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,7 @@ func GitFsck() {
log.Trace("Doing: GitFsck")

if err := x.
Where("id>0").
Where("id>0").BufferSize(setting.IterateBufferSize).
Iterate(new(Repository),
func(idx int, bean interface{}) error {
repo := bean.(*Repository)
Expand All @@ -2167,7 +2167,7 @@ func GitFsck() {
func GitGcRepos() error {
args := append([]string{"gc"}, setting.Git.GCArgs...)
return x.
Where("id > 0").
Where("id > 0").BufferSize(setting.IterateBufferSize).
Iterate(new(Repository),
func(idx int, bean interface{}) error {
repo := bean.(*Repository)
Expand Down
2 changes: 1 addition & 1 deletion models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ func ChangeUserName(u *User, newUserName string) (err error) {
}

// Delete all local copies of repository wiki that user owns.
if err = x.
if err = x.BufferSize(setting.IterateBufferSize).
Where("owner_id=?", u.ID).
Iterate(new(Repository), func(idx int, bean interface{}) error {
repo := bean.(*Repository)
Expand Down
20 changes: 11 additions & 9 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,16 @@ var (
ShowFooterTemplateLoadTime bool

// Global setting objects
Cfg *ini.File
CustomPath string // Custom directory path
CustomConf string
CustomPID string
ProdMode bool
RunUser string
IsWindows bool
HasRobotsTxt bool
InternalToken string // internal access token
Cfg *ini.File
CustomPath string // Custom directory path
CustomConf string
CustomPID string
ProdMode bool
RunUser string
IsWindows bool
HasRobotsTxt bool
InternalToken string // internal access token
IterateBufferSize int
)

// DateLang transforms standard language locale name to corresponding value in datetime plugin.
Expand Down Expand Up @@ -873,6 +874,7 @@ func NewContext() {
log.Fatal(4, "Error saving generated JWT Secret to custom config: %v", err)
}
}
IterateBufferSize = Cfg.Section("database").Key("ITERATE_BUFFER_SIZE").MustInt(50)

sec = Cfg.Section("attachment")
AttachmentPath = sec.Key("PATH").MustString(path.Join(AppDataPath, "attachments"))
Expand Down