0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-12 13:01:19 +01:00

In PushMirrorsIterate and MirrorsIterate if limit is negative do not set it (#20837)

This commit is contained in:
zeripath 2022-08-19 03:12:00 +01:00 committed by GitHub
parent 3aa5749d53
commit fc4680ea71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View file

@ -107,12 +107,14 @@ func DeleteMirrorByRepoID(repoID int64) error {
// MirrorsIterate iterates all mirror repositories. // MirrorsIterate iterates all mirror repositories.
func MirrorsIterate(limit int, 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). sess := db.GetEngine(db.DefaultContext).
Where("next_update_unix<=?", time.Now().Unix()). Where("next_update_unix<=?", time.Now().Unix()).
And("next_update_unix!=0"). And("next_update_unix!=0").
OrderBy("updated_unix ASC"). OrderBy("updated_unix ASC")
Limit(limit). if limit > 0 {
Iterate(new(Mirror), f) sess = sess.Limit(limit)
}
return sess.Iterate(new(Mirror), f)
} }
// InsertMirror inserts a mirror to database // InsertMirror inserts a mirror to database

View file

@ -129,10 +129,12 @@ func GetPushMirrorsSyncedOnCommit(repoID int64) ([]*PushMirror, error) {
// PushMirrorsIterate iterates all push-mirror repositories. // PushMirrorsIterate iterates all push-mirror repositories.
func PushMirrorsIterate(ctx context.Context, limit int, f func(idx int, bean interface{}) error) error { 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()). Where("last_update + (`interval` / ?) <= ?", time.Second, time.Now().Unix()).
And("`interval` != 0"). And("`interval` != 0").
OrderBy("last_update ASC"). OrderBy("last_update ASC")
Limit(limit). if limit > 0 {
Iterate(new(PushMirror), f) sess = sess.Limit(limit)
}
return sess.Iterate(new(PushMirror), f)
} }