diff options
author | zeripath <art27@cantab.net> | 2022-08-19 03:12:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-18 22:12:00 -0400 |
commit | fc4680ea712fdf89065db882cd9d67946d004500 (patch) | |
tree | a8af9ce88baeb9ee4669f5615c7eb162a3c7872c /models | |
parent | 3aa5749d538d058c26fe79043612ff8191d1a247 (diff) | |
download | gitea-fc4680ea712fdf89065db882cd9d67946d004500.tar.gz gitea-fc4680ea712fdf89065db882cd9d67946d004500.zip |
In PushMirrorsIterate and MirrorsIterate if limit is negative do not set it (#20837)
Diffstat (limited to 'models')
-rw-r--r-- | models/repo/mirror.go | 10 | ||||
-rw-r--r-- | 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 6a95bc48c4..297ffd594a 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 02ffcbee76..38d6e72019 100644 --- a/models/repo/pushmirror.go +++ b/models/repo/pushmirror.go @@ -129,10 +129,12 @@ func GetPushMirrorsSyncedOnCommit(repoID int64) ([]*PushMirror, error) { // PushMirrorsIterate iterates all push-mirror repositories. func PushMirrorsIterate(ctx context.Context, limit int, f func(idx int, bean interface{}) error) error { - return db.GetEngine(ctx). + sess := db.GetEngine(ctx). 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) } |