From 0230f1e1aa8c6b43aa84b9ff44f58e08e26d2039 Mon Sep 17 00:00:00 2001 From: zeripath Date: Tue, 23 Aug 2022 17:38:52 +0100 Subject: [PATCH] In PushMirrorsIterate and MirrorsIterate if limit is negative do not set it (#20837) (#20899) Backport #20837 Co-authored-by: Lunny Xiao Co-authored-by: techknowlogick --- models/repo/mirror.go | 10 ++++++---- models/repo/pushmirror.go | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/models/repo/mirror.go b/models/repo/mirror.go index 6a95bc48c44..297ffd594a7 100644 --- a/models/repo/mirror.go +++ b/models/repo/mirror.go @@ -107,12 +107,14 @@ func DeleteMirrorByRepoID(repoID int64) error { // MirrorsIterate iterates all mirror repositories. func MirrorsIterate(limit int, f func(idx int, bean interface{}) error) error { - return db.GetEngine(db.DefaultContext). + sess := 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) + OrderBy("updated_unix ASC") + if limit > 0 { + sess = sess.Limit(limit) + } + return sess.Iterate(new(Mirror), f) } // InsertMirror inserts a mirror to database diff --git a/models/repo/pushmirror.go b/models/repo/pushmirror.go index 048c0c3487b..42dbaef3fd6 100644 --- a/models/repo/pushmirror.go +++ b/models/repo/pushmirror.go @@ -95,10 +95,12 @@ func GetPushMirrorsByRepoID(repoID int64) ([]*PushMirror, error) { // PushMirrorsIterate iterates all push-mirror repositories. func PushMirrorsIterate(limit int, f func(idx int, bean interface{}) error) error { - return db.GetEngine(db.DefaultContext). + sess := 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) + OrderBy("last_update ASC") + if limit > 0 { + sess = sess.Limit(limit) + } + return sess.Iterate(new(PushMirror), f) }