diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-03-01 03:41:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-28 20:41:06 +0100 |
commit | b75ad7b87f122a1386cb0e576ce83cc000f6d010 (patch) | |
tree | 14835b769ae37a82e463e38b03f49d0bea515b69 /models | |
parent | 59959ab222cee6e679aa373b37c6c4bce348e825 (diff) | |
download | gitea-b75ad7b87f122a1386cb0e576ce83cc000f6d010.tar.gz gitea-b75ad7b87f122a1386cb0e576ce83cc000f6d010.zip |
Improve mirror iterator (#18928)
* Improve mirror iterator
* fix test
Diffstat (limited to 'models')
-rw-r--r-- | models/repo/mirror.go | 3 | ||||
-rw-r--r-- | models/repo/pushmirror.go | 3 | ||||
-rw-r--r-- | models/repo/pushmirror_test.go | 2 |
3 files changed, 5 insertions, 3 deletions
diff --git a/models/repo/mirror.go b/models/repo/mirror.go index e73226534e..8494331ff7 100644 --- a/models/repo/mirror.go +++ b/models/repo/mirror.go @@ -120,11 +120,12 @@ func DeleteMirrorByRepoID(repoID int64) error { } // MirrorsIterate iterates all mirror repositories. -func MirrorsIterate(f func(idx int, bean interface{}) error) error { +func MirrorsIterate(limit int, f func(idx int, bean interface{}) error) error { return db.GetEngine(db.DefaultContext). Where("next_update_unix<=?", time.Now().Unix()). And("next_update_unix!=0"). OrderBy("updated_unix ASC"). + Limit(limit). Iterate(new(Mirror), f) } diff --git a/models/repo/pushmirror.go b/models/repo/pushmirror.go index bf39bb1ac0..b5c6411bd6 100644 --- a/models/repo/pushmirror.go +++ b/models/repo/pushmirror.go @@ -101,10 +101,11 @@ func GetPushMirrorsByRepoID(repoID int64) ([]*PushMirror, error) { } // PushMirrorsIterate iterates all push-mirror repositories. -func PushMirrorsIterate(f func(idx int, bean interface{}) error) error { +func PushMirrorsIterate(limit int, f func(idx int, bean interface{}) error) error { return db.GetEngine(db.DefaultContext). Where("last_update + (`interval` / ?) <= ?", time.Second, time.Now().Unix()). And("`interval` != 0"). OrderBy("last_update ASC"). + Limit(limit). Iterate(new(PushMirror), f) } diff --git a/models/repo/pushmirror_test.go b/models/repo/pushmirror_test.go index eff31fbac2..83cf86131f 100644 --- a/models/repo/pushmirror_test.go +++ b/models/repo/pushmirror_test.go @@ -40,7 +40,7 @@ func TestPushMirrorsIterate(t *testing.T) { time.Sleep(1 * time.Millisecond) - PushMirrorsIterate(func(idx int, bean interface{}) error { + PushMirrorsIterate(1, func(idx int, bean interface{}) error { m, ok := bean.(*PushMirror) assert.True(t, ok) assert.Equal(t, "test-1", m.RemoteName) |