summaryrefslogtreecommitdiffstats
path: root/models/context.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-01-21 04:01:19 +0800
committerzeripath <art27@cantab.net>2020-01-20 20:01:19 +0000
commitd92781bf941972761177ac9e07441f8893758fd3 (patch)
treed5d00f8f42fc75ee497bfd8cd52d3b431f1d9b67 /models/context.go
parent27c6b8fc07eab2dd579b94cd92136738ace61706 (diff)
downloadgitea-d92781bf941972761177ac9e07441f8893758fd3.tar.gz
gitea-d92781bf941972761177ac9e07441f8893758fd3.zip
Refactor repository check and sync functions (#9854)
Move more general repository functions out of models/repo.go
Diffstat (limited to 'models/context.go')
-rw-r--r--models/context.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/models/context.go b/models/context.go
index 5f47c595a2..6b8b9af570 100644
--- a/models/context.go
+++ b/models/context.go
@@ -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)
+}