1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Refactor repository check and sync functions (#9854)

Move more general repository functions out of models/repo.go
This commit is contained in:
Lunny Xiao
2020-01-21 04:01:19 +08:00
committed by zeripath
parent 27c6b8fc07
commit d92781bf94
12 changed files with 313 additions and 210 deletions

View File

@@ -4,6 +4,12 @@
package models
import (
"code.gitea.io/gitea/modules/setting"
"xorm.io/builder"
)
// DBContext represents a db context
type DBContext struct {
e Engine
@@ -53,3 +59,10 @@ func WithTx(f func(ctx DBContext) error) error {
sess.Close()
return err
}
// Iterate iterates the databases and doing something
func Iterate(ctx DBContext, tableBean interface{}, cond builder.Cond, fun func(idx int, bean interface{}) error) error {
return ctx.e.Where(cond).
BufferSize(setting.Database.IterateBufferSize).
Iterate(tableBean, fun)
}