Use buffersize to reduce database connection when iterate (#2724)

* use buffersize to reduce database connection when iterate

* fix typo

* add default value on app.ini comment
tokarchuk/v1.17
Lunny Xiao 7 years ago committed by GitHub
parent 2112eb8741
commit 985a39590b
  1. 2
      conf/app.ini
  2. 2
      models/migrations/v19.go
  3. 2
      models/migrations/v22.go
  4. 2
      models/migrations/v26.go
  5. 4
      models/repo.go
  6. 2
      models/user.go
  7. 20
      modules/setting/setting.go

2
conf/app.ini vendored

@ -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

@ -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)

@ -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)

@ -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)

@ -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)
@ -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)

@ -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)

@ -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.
@ -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"))

Loading…
Cancel
Save